return early from de_position with ?

This commit is contained in:
kageru 2020-06-20 23:53:32 +02:00
parent ff215567d5
commit aa770c7b1c
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -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<Option<Position>, 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)
}