Add UnitResponse for commands without response payload
This commit is contained in:
parent
b31abb7320
commit
74ccb40df5
19
src/lib.rs
19
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<UnitResponse, _> = 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<UnitResponse, _> = deserialize_response(failure.lines());
|
||||
assert_eq!(
|
||||
r,
|
||||
Err(error::Error::from_str(r#"[2@0] {consume} wrong number of arguments for "consume""#))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,11 @@ pub struct Track {
|
|||
pub composer: Option<String>,
|
||||
}
|
||||
|
||||
/// 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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user