How to use thiserror crate

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(())
}