From aa770c7b1ccbb2c85893fc62c016a5888d378ce7 Mon Sep 17 00:00:00 2001 From: kageru Date: Sat, 20 Jun 2020 23:53:32 +0200 Subject: [PATCH] return early from de_position with ? --- src/structs.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/structs.rs b/src/structs.rs index 3ef2304..51e647d 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -99,14 +99,13 @@ mod helpers { /// The input string here is either a number or two numbers separated by `SEPARATOR`. pub fn de_position<'de, D>(deserializer: D) -> Result, D::Error> where D: de::Deserializer<'de> { - if let Ok(s) = String::deserialize(deserializer) { - let mut ints = s.split(SEPARATOR).map(u16::from_str); - if let Some(Ok(n)) = ints.next() { - return Ok(Some(Position { - item_position: n, - total_items: ints.next().and_then(Result::ok), - })); - } + let s = String::deserialize(deserializer)?; + let mut ints = s.split(SEPARATOR).map(u16::from_str); + if let Some(Ok(n)) = ints.next() { + return Ok(Some(Position { + item_position: n, + total_items: ints.next().and_then(Result::ok), + })); } Ok(None) }