diff --git a/src/lib.rs b/src/lib.rs index 361ef9d..cbb5032 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ mod error; use error::{Error, MpdResult}; use itertools::Itertools; mod structs; -pub use structs::{Position, State, Stats, Status, Track}; +pub use structs::{Position, State, Stats, Status, Track, UnitResponse}; /// some unprintable character to separate repeated keys const SEPARATOR: char = '\x02'; @@ -288,7 +288,8 @@ artists: 2841 albums: 2455 songs: 40322 db_playtime: 11620284 -db_update: 1588433046"; +db_update: 1588433046 +OK"; let s: Stats = deserialize_response(input_str.lines()).unwrap(); assert_eq!( s, @@ -303,4 +304,18 @@ db_update: 1588433046"; } ); } + + #[test] + fn de_unit_response_test() { + let success = "OK"; + let r: Result = deserialize_response(success.lines()); + assert_eq!(r, Ok(UnitResponse {})); + + let failure = r#"ACK [2@0] {consume} wrong number of arguments for "consume""#; + let r: Result = deserialize_response(failure.lines()); + assert_eq!( + r, + Err(error::Error::from_str(r#"[2@0] {consume} wrong number of arguments for "consume""#)) + ); + } } diff --git a/src/structs.rs b/src/structs.rs index ef277ad..cf22f20 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -47,6 +47,11 @@ pub struct Track { pub composer: Option, } +/// An empty struct that can be used as the response data for commands that only ever return `OK` +/// or an error message, e.g. `consume` or other boolean toggles. +#[derive(Deserialize, PartialEq, Debug)] +pub struct UnitResponse {} + /// The position of an item in a list with an optional total length. /// Can be used for e.g. track number, /// where `Position { 3, 12 }` represents track 3 of a CD with 12 tracks,