simplify split parsing

This commit is contained in:
kageru 2020-06-21 23:11:41 +02:00
parent 9fb4513fbc
commit b31abb7320
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -4,7 +4,7 @@ mod error;
use error::{Error, MpdResult}; use error::{Error, MpdResult};
use itertools::Itertools; use itertools::Itertools;
mod structs; mod structs;
pub use structs::{Position, Stats, Status, Track, State}; pub use structs::{Position, State, Stats, Status, Track};
/// some unprintable character to separate repeated keys /// some unprintable character to separate repeated keys
const SEPARATOR: char = '\x02'; const SEPARATOR: char = '\x02';
@ -18,9 +18,8 @@ pub fn deserialize_response<'a, I: Iterator<Item = &'a str>, T: de::DeserializeO
return Err(Error::from_str(message.trim())); return Err(Error::from_str(message.trim()));
} }
let mut fields = line.splitn(2, ": "); match line.splitn(2, ": ").next_tuple() {
match (fields.next(), fields.next()) { Some((k, v)) => {
(Some(k), Some(v)) => {
if let Some(existing) = map.get_mut(k) { if let Some(existing) = map.get_mut(k) {
existing.push(SEPARATOR); existing.push(SEPARATOR);
existing.push_str(v); existing.push_str(v);