commands: deduplicate logic in macros, add more macros
Build and test / build (push) Successful in 59s
Build and test / check (push) Failing after 1m2s
Build and test / test (push) Successful in 1m40s
Build and test / docs (push) Successful in 1m27s

This commit is contained in:
2025-02-23 19:16:58 +01:00
parent ed7f9a6917
commit 380a4aed2c
9 changed files with 154 additions and 152 deletions
+4 -12
View File
@@ -1,6 +1,6 @@
use crate::{
commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
get_next_and_parse_property, Command, Request, RequestParserError, RequestParserResult,
ResponseAttributes, ResponseParserError,
},
common::{SongId, SongPosition},
@@ -39,17 +39,9 @@ impl Command for AddId {
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> {
let parts: Vec<_> = parts.into();
let (key, value) = parts.first().ok_or(ResponseParserError::UnexpectedEOF)?;
debug_assert!(key == &"Id");
let value = match value {
GenericResponseValue::Text(value) => value,
GenericResponseValue::Binary(_) => {
return Err(ResponseParserError::UnexpectedPropertyType("Id", "Binary"))
}
};
let id = value
.parse()
.map_err(|_| ResponseParserError::InvalidProperty("Id", value.to_owned()))?;
let mut iter = parts.into_iter();
let (key, id) = get_next_and_parse_property!(iter, Text);
debug_assert!(key == "Id");
Ok(AddIdResponse { id })
}
}