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 itertools::Itertools;
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
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()));
}
let mut fields = line.splitn(2, ": ");
match (fields.next(), fields.next()) {
(Some(k), Some(v)) => {
match line.splitn(2, ": ").next_tuple() {
Some((k, v)) => {
if let Some(existing) = map.get_mut(k) {
existing.push(SEPARATOR);
existing.push_str(v);