Lines
0 %
Functions
use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
ResponseParserError,
};
pub struct StickerNames;
pub type StickerNamesResponse = Vec<String>;
impl Command for StickerNames {
type Response = StickerNamesResponse;
const COMMAND: &'static str = "stickernames";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
debug_assert!(parts.next().is_none());
Ok((Request::StickerNames, ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.0.iter().all(|(k, _)| *k == "name"));
let list = parts
.0
.iter()
.map(|(_, v)| match v {
GenericResponseValue::Text(value) => Ok(value.to_string()),
GenericResponseValue::Binary(_) => Err(
ResponseParserError::UnexpectedPropertyType("name", "Binary"),
),
})
.collect::<Result<Vec<_>, ResponseParserError>>()?;
Ok(list)