From e99d57d6cdb8760d4351c9f0ed9f5b0285b26e37 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 13 Mar 2021 21:25:20 +0100 Subject: Replace `unwrap`s with try in non-main functions --- src/main.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index d98d998..45d4820 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,10 +40,10 @@ fn main() { } fn get_email_body(email: &[u8]) -> Result> { - let email = mailparse::parse_mail(&email).unwrap(); + let email = mailparse::parse_mail(&email)?; if email.subparts.is_empty() { - let body = email.get_body().unwrap(); + let body = email.get_body()?; return Ok(body); } else { @@ -54,7 +54,7 @@ fn get_email_body(email: &[u8]) -> Result> { if header.get_key() == "Content-Type" && header.get_value().starts_with("text/plain") { - return Ok(part.get_body().unwrap()); + return Ok(part.get_body()?); } } } @@ -64,12 +64,12 @@ fn get_email_body(email: &[u8]) -> Result> { } fn write_attribution(config: &str) -> Result<(), Box> { - let xdg_dirs = xdg::BaseDirectories::with_prefix(PROGRAM_NAME).unwrap(); + let xdg_dirs = xdg::BaseDirectories::with_prefix(PROGRAM_NAME)?; - let muttrc_path = xdg_dirs.place_data_file(MUTTRC_FILENAME).unwrap(); + let muttrc_path = xdg_dirs.place_data_file(MUTTRC_FILENAME)?; - let mut file = File::create(muttrc_path).unwrap(); - file.write_all(config.as_bytes()).unwrap(); + let mut file = File::create(muttrc_path)?; + file.write_all(config.as_bytes())?; Ok(()) } -- cgit v1.2.3