Result<T, Error>
This is a reasonable return type to use throughout your application but also
for fn main; if you do, failures will be printed along with any
[context][Context] and a backtrace if one was captured.
anyhow::Result may be used with one or two type parameters.
use anyhow::Result;
# const IGNORE: &str = stringify! {
fn demo1() -> Result<T> {...}
fn demo2() -> Result<T, OtherError> {...}
# };
Example
# pub trait Deserialize {}
#
# mod serde_json {
# use super::Deserialize;
# use std::io;
#
# pub fn from_str<T: Deserialize>(json: &str) -> io::Result<T> {
# unimplemented!()
# }
# }
#
# #[derive(Debug)]
# struct ClusterMap;
#
# impl Deserialize for ClusterMap {}
#
use anyhow::Result;
fn main() -> Result<()> {
# return Ok(());
let config = std::fs::read_to_string("cluster.json")?;
let map: ClusterMap = serde_json::from_str(&config)?;
println!("cluster info: {:#?}", map);
Ok(())
}