summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hurst <tom@hur.st>2018-09-07 02:19:40 +0100
committerKartikaya Gupta (kats) <staktrace@users.noreply.github.com>2018-09-07 11:51:51 -0400
commit59a9e608cc6b9ce7af946d9260056a86cbbcfe75 (patch)
tree3beb44bea6a5d10374434209e550ccf5644c5e6b
parent87eb8897eed8f9952c313a642f111fd1d255849e (diff)
downloadmailparse-59a9e608cc6b9ce7af946d9260056a86cbbcfe75.tar.gz
mailparse-59a9e608cc6b9ce7af946d9260056a86cbbcfe75.tar.xz
Replace try_none! with ?
-rw-r--r--src/lib.rs12
-rw-r--r--src/macros.rs8
2 files changed, 5 insertions, 15 deletions
diff --git a/src/lib.rs b/src/lib.rs
index e7a74a9..450c45a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -9,8 +9,6 @@ use std::collections::BTreeMap;
use encoding::Encoding;
-#[macro_use]
-mod macros;
mod dateparse;
pub use dateparse::dateparse;
@@ -147,15 +145,15 @@ impl<'a> MailHeader<'a> {
}
fn decode_word(&self, encoded: &str) -> Option<String> {
- let ix_delim1 = try_none!(encoded.find('?'));
- let ix_delim2 = try_none!(find_from(encoded, ix_delim1 + 1, "?"));
+ let ix_delim1 = encoded.find('?')?;
+ let ix_delim2 = find_from(encoded, ix_delim1 + 1, "?")?;
let charset = &encoded[0..ix_delim1];
let transfer_coding = &encoded[ix_delim1 + 1..ix_delim2];
let input = &encoded[ix_delim2 + 1..];
let decoded = match transfer_coding {
- "B" | "b" => try_none!(base64::decode(input.as_bytes()).ok()),
+ "B" | "b" => base64::decode(input.as_bytes()).ok()?,
"Q" | "q" => {
// The quoted_printable module does a trim_right on the input, so if
// that affects the output we should save and restore the trailing
@@ -169,11 +167,11 @@ impl<'a> MailHeader<'a> {
to_decode[trimmed.len()..].as_bytes(),
);
}
- try_none!(d.ok())
+ d.ok()?
}
_ => return None,
};
- let charset_conv = try_none!(encoding::label::encoding_from_whatwg_label(charset));
+ let charset_conv = encoding::label::encoding_from_whatwg_label(charset)?;
charset_conv
.decode(&decoded, encoding::DecoderTrap::Replace)
.ok()
diff --git a/src/macros.rs b/src/macros.rs
deleted file mode 100644
index 980f0eb..0000000
--- a/src/macros.rs
+++ /dev/null
@@ -1,8 +0,0 @@
-macro_rules! try_none {
- ( $x:expr ) => {{
- match $x {
- Some(v) => v,
- None => return None,
- }
- }}
-}