From 5d050d064e3249e93182d4040bc0c435432960b8 Mon Sep 17 00:00:00 2001 From: Max Verevkin Date: Sun, 3 Apr 2022 01:02:28 +0300 Subject: simplify de_last a little --- src/i3bar_protocol.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/i3bar_protocol.rs b/src/i3bar_protocol.rs index 7da061c..6bc0533 100644 --- a/src/i3bar_protocol.rs +++ b/src/i3bar_protocol.rs @@ -165,19 +165,19 @@ impl Protocol { /// Deserialize the last complete object. Returns (`remaining`, `object`). See tests for examples. fn de_last<'a, T: Deserialize<'a>>(mut s: &'a str) -> SerdeResult<(&'a str, Option)> { let mut last = None; - s = s.trim_start_matches(|x: char| x.is_ascii_whitespace() || x == ','); + let mut tmp; loop { - let (rem, obj) = de_once(s)?; - last = match obj { + (s, tmp) = de_once(s)?; + last = match tmp { Some(obj) => Some(obj), - None => return Ok((rem, last)), + None => return Ok((s, last)), }; - s = rem.trim_start_matches(|x: char| x.is_ascii_whitespace() || x == ','); } } /// Deserialize the first complete object. Returns (`remaining`, `object`). fn de_once<'a, T: Deserialize<'a>>(s: &'a str) -> SerdeResult<(&'a str, Option)> { + let s = s.trim_start_matches(|x: char| x.is_ascii_whitespace() || x == ','); let mut de = Deserializer::from_str(s).into_iter(); match de.next() { Some(Ok(obj)) => Ok((&s[de.byte_offset()..], Some(obj))), -- cgit v1.3.1