Skip to main content

parse_response

Function parse_response 

Source
pub fn parse_response<'a, I: Iterator<Item = &'a str>, T: DeserializeOwned>(
    input: I,
) -> Result<T, Error>
Expand description

Parse an interator of string slices into T, returning Ok(T) if the data could be deserialized and the MPD response ended with OK or Error if the deserialization failed or MPD sent an error message.

let response = "file: 01 Track.flac
Last-Modified: 2018-03-07T13:11:43Z
duration: 123.45
Pos: 1
Id: 2
OK";
let parsed: Track = parse_response(response.lines()).unwrap();

assert_eq!(parsed.file, String::from("01 Track.flac"));
assert_eq!(parsed.duration, Some(Duration::from_secs_f64(123.45)));

For responses that contain multiple instances of a struct (like playlists), see parse_response_vec.