Program entry point and top-level command routing.
Tutorial overview
mainis the required entry point for a Rust binary crate.- We delegate to [
run] so we can return aResultand use?for ergonomic error propagation. - The CLI is parsed via
clapderive macros into typed enums/structs. - We then dispatch to feature modules (
commands::*) usingmatch.
Rust concepts used here
Result<T, E>and the?operator for error propagation.- Pattern matching (
match,if let,while let) to unpack enums/Options. - Trait objects (
&dyn Error) for printing a chain of errors. - Borrowing and references (
&name,&args) to avoid cloning.
Source:
src/main.rs