From 0d01918713528cf60cf1f70692aecf213a056024 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 1 Dec 2019 17:00:50 +0100 Subject: [PATCH] examples: Remove all unwrap()s. --- xmpp-parsers/examples/generate-caps.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/xmpp-parsers/examples/generate-caps.rs b/xmpp-parsers/examples/generate-caps.rs index 643b7320..0d4594d0 100644 --- a/xmpp-parsers/examples/generate-caps.rs +++ b/xmpp-parsers/examples/generate-caps.rs @@ -12,7 +12,7 @@ use xmpp_parsers::{ disco::DiscoInfoResult, ecaps2::{compute_disco as compute_disco_ecaps2, hash_ecaps2, ECaps2}, hashes::Algo, - Element, + Element, Error, }; fn get_caps(disco: &DiscoInfoResult, node: String) -> Result { @@ -21,18 +21,18 @@ fn get_caps(disco: &DiscoInfoResult, node: String) -> Result { Ok(Caps::new(node, caps_hash)) } -fn get_ecaps2(disco: &DiscoInfoResult) -> Result { - let ecaps2_data = compute_disco_ecaps2(&disco).unwrap(); +fn get_ecaps2(disco: &DiscoInfoResult) -> Result { + let ecaps2_data = compute_disco_ecaps2(&disco)?; let ecaps2_sha256 = hash_ecaps2(&ecaps2_data, Algo::Sha_256)?; let ecaps2_sha3_256 = hash_ecaps2(&ecaps2_data, Algo::Sha3_256)?; Ok(ECaps2::new(vec![ecaps2_sha256, ecaps2_sha3_256])) } -fn main() -> Result<(), ()> { +fn main() -> Result<(), Box> { let args: Vec<_> = env::args().collect(); if args.len() != 2 { println!("Usage: {} ", args[0]); - return Err(()); + std::process::exit(1); } let node = args[1].clone(); @@ -42,15 +42,15 @@ fn main() -> Result<(), ()> { let stdin = io::stdin(); let mut data = String::new(); let mut handle = stdin.lock(); - handle.read_to_string(&mut data).unwrap(); + handle.read_to_string(&mut data)?; // Parse the payload into a DiscoInfoResult. - let elem: Element = data.parse().unwrap(); - let disco = DiscoInfoResult::try_from(elem).unwrap(); + let elem: Element = data.parse()?; + let disco = DiscoInfoResult::try_from(elem)?; // Compute both kinds of caps. - let caps = get_caps(&disco, node).unwrap(); - let ecaps2 = get_ecaps2(&disco).unwrap(); + let caps = get_caps(&disco, node)?; + let ecaps2 = get_ecaps2(&disco)?; // Print them. let caps_elem = Element::from(caps);