Add thiserror to Cargo.toml, derive the Error trait on your enum, and use it to handle custom errors cleanly.
Add thiserror to your Cargo.toml dependencies, derive the Error trait on your custom error type, and use it with ? or Result.
[dependencies]
thiserror = "1.0"
use thiserror::Error;
#[derive(Error, Debug)]
enum MyError {
#[error("Invalid input: {0}")]
InvalidInput(String),
}
fn process() -> Result<(), MyError> {
Ok(())
}
The thiserror crate lets you create custom error types in Rust without writing repetitive boilerplate code. It automatically handles how your errors are displayed and formatted when something goes wrong. Think of it as a shortcut that turns your custom error definitions into fully functional error handlers instantly.