1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
//! `MainResult` with the [`Tree`] format. //! //! Run: `cargo run --example tree` //! //! Output: //! //! ```text //! Error: failed to load config //! └── failed to read file //! └── No such file or directory (os error 2) //! ``` use std::{fs, io}; use errortools::{MainResult, Tree}; #[derive(Debug, thiserror::Error)] enum AppError { #[error("failed to load config")] Config(#[source] ConfigError), } #[derive(Debug, thiserror::Error)] enum ConfigError { #[error("failed to read file")] Read(#[source] io::Error), } fn main() -> MainResult<AppError, Tree> { fs::read_to_string("does-not-exist.toml") .map_err(ConfigError::Read) .map_err(AppError::Config)?; Ok(()) }