Here are some best practices for error handling in Rust programming that I've found effective:
For tests and examples, use "box dyn error" instead of "anyhow."
Prefer the "?" pattern over "unwrap" or "expect," even in tests and examples, to align with production coding standards.
"Box dyn error" is excellent for error passthrough, as are `map_err` and `ok_or` with static strings and formatted strings.
In production code, use an enum with fully descriptive variant names and favor struct variants with clear names over tuple variants.
Avoid relying on the display to convey the meaning of error variants.
In web or device applications, human error rendering might not occur at the enum/type level, so using Debug for display may suffice.
For web or device applications, using Serialize for errors that need to be logged or sent to the client for display can be a powerful and straightforward pattern.
Prioritize clarity in error naming (variants) and focus on consistency as the code develops.
Don't be afraid of mediumlength enum variant names; remember, type refactoring is straightforward.
In summary, start with progressive and clear practices, and become more structured as the code matures.
== Jeremy Chone:
Patreon / jeremychone Any help is a big help (for Rust educational content)
Twitter / jeremychone
Discord generalrust / discord
Discord rust10x / discord
Rust10x https://rust10x.com'>https://rust10x.com Rust resources for production coding.
Big thanks to CrabNebula (https://crabnebula.dev/) for sponsoring this channel.
== Rust10x AI / OpenAI / Ollama
Rust OpenAI API Tutorial: • Learn Rust OpenAI API Building AI B...
Rust Ollama Tutorial: • Rust Ollama By Examples 4 Chapters ...
== Rust10x Web App production coding:
Episode 01: • Rust Axum Production Coding (E01 Ru...
Episode 02: • Rust SeaQuery + SQLX + ModQL (E02 ...
Episode 03: • Rust Workspace Production By Example ...
Episode 04: • Rust Argon 2 Password Hashing with Mu...
Episode 05.1: • Rust RPC Router Axum/Tower/Bevy Sty...
Web Site: https://rust10x.com'>https://rust10x.com/webapp
GitHub: https://github.com/rust10x/rustwebapp
Discord rust10x / discord
Patreon / jeremychone Any help is a big help (for Rust Production Coding educational content)
== Other
Other popular Rust Programming videos:
Rust Web App Production Coding Blueprint • Rust Axum Production Coding (E01 Ru...
Rust Axum Full Course • Rust Axum Full Course Web Developme...
Rust Type State Builder Pattern • Rust Programming: TypeState Builder P...
Quick Start Code Layout • Rust Simple Code Layout (start simp...
AWESOMEAPP Full Overview Rust template for building Awesome Desktop Application: • Building Awesome Desktop App with Rus...
Tauri Quick Introduction (Desktop App wit Rust Programming): • Rust Tauri 1.0 Quick Intro Rust D...
Rust Web App tutorials series: • Rust Web App 1/3 Data Access
Rust Bevy Full Tutorial Game Development with Rust: • Rust Bevy Full Tutorial Game Develo...
Rust for Java Developers series: • Rust for Java Developers 1/3 Introd...
Playlists:
Rust AI Programming Series: • Rust GenAI Programming Series, Tutorials
Rust Web App Production Coding Series: • JC Rust Production Coding Web App...
Rust For Desktop App: • JC Rust Programming for Desktop App
Everything Rust Programming Tutorials, Courses, Tips, Examples: • JC Rust Everything Rust Programmi...
Rust Programming for Web Development: • JC Rust Programming for Web Develop...
Rust Courses: • Rust Course 2021 by the book | RustLang
Rust for Java Developers: • Rust for Java Developers
Rust10x Coding Resources for Production Coding in Rust. ➜ https://rust10x.com'>https://rust10x.com
Other notes:
ScreenBrush for the green lines. (Gromit seems to be the equivalent on Linux)
Sketchapp for some graphics.
Davinci Resolve and Fusion video editing.
VSCode with Google Material icon themes (with some customization)