miette

Type Alias Result

Source
pub type Result<T, E = Report> = Result<T, E>;
Expand description

type alias for Result<T, Report>

This is a reasonable return type to use throughout your application but also for main(). If you do, failures will be printed along with a backtrace if one was captured.

miette::Result may be used with one or two type parameters.

use miette::Result;

fn demo1() -> Result<T> {...}
           // ^ equivalent to std::result::Result<T, miette::Error>

fn demo2() -> Result<T, OtherError> {...}
           // ^ equivalent to std::result::Result<T, OtherError>

§Example

use miette::{IntoDiagnostic, Result};

fn main() -> Result<()> {
    let config = std::fs::read_to_string("cluster.json").into_diagnostic()?;
    let map: ClusterMap = serde_json::from_str(&config).into_diagnostic()?;
    println!("cluster info: {:#?}", map);
    Ok(())
}

§anyhow/eyre Users

You can just replace uses of anyhow::Result/eyre::Result with miette::Result.

Aliased Type§

enum Result<T, E = Report> {
    Ok(T),
    Err(E),
}

Variants§

§1.0.0

Ok(T)

Contains the success value

§1.0.0

Err(E)

Contains the error value