Files
empidee/src/commands/music_database/readcomments.rs
T

46 lines
1.3 KiB
Rust

use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use crate::{
commands::{Command, CommandResponse, ResponseParserError, single_item_command_request},
common::types::Uri,
response_tokenizer::{GenericResponseValue, ResponseAttributes},
};
pub struct ReadComments;
single_item_command_request!(ReadComments, "readcomments", Uri);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ReadCommentsResponse(HashMap<String, String>);
impl CommandResponse<'_> for ReadCommentsResponse {
fn into_response_enum(self) -> crate::Response {
todo!()
}
fn from_response_enum(response: crate::Response) -> Option<Self> {
todo!()
}
fn parse(parts: ResponseAttributes<'_>) -> Result<Self, ResponseParserError<'_>> {
let parts: HashMap<_, _> = parts.into_map()?;
let comments = parts
.iter()
.map(|(k, v)| match v {
GenericResponseValue::Text(s) => Ok((k.to_string(), s.to_string())),
GenericResponseValue::Binary(_) => Err(ResponseParserError::SyntaxError(1, k)),
})
.collect::<Result<HashMap<_, _>, ResponseParserError>>()?;
Ok(ReadCommentsResponse(comments))
}
}
impl Command<'_, '_> for ReadComments {
type Request = ReadCommentsRequest;
type Response = ReadCommentsResponse;
}