further simplify de_position

This commit is contained in:
kageru 2020-06-21 00:00:24 +02:00
parent aa770c7b1c
commit 9b73d95340
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -100,11 +100,11 @@ mod helpers {
pub fn de_position<'de, D>(deserializer: D) -> Result<Option<Position>, D::Error>
where D: de::Deserializer<'de> {
let s = String::deserialize(deserializer)?;
let mut ints = s.split(SEPARATOR).map(u16::from_str);
if let Some(Ok(n)) = ints.next() {
let mut ints = s.split(SEPARATOR).filter_map(|s| u16::from_str(s).ok());
if let Some(n) = ints.next() {
return Ok(Some(Position {
item_position: n,
total_items: ints.next().and_then(Result::ok),
total_items: ints.next(),
}));
}
Ok(None)