Lines
0 %
Functions
use crate::commands::{
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, get_next_property,
};
pub struct StickerGet;
pub type StickerGetResponse = String;
impl Command for StickerGet {
type Response = StickerGetResponse;
const COMMAND: &'static str = "sticker get";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
let sticker_type = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let sticker_type = sticker_type
.parse()
.map_err(|_| RequestParserError::SyntaxError(1, sticker_type.to_owned()))?;
let uri = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let uri = uri
.map_err(|_| RequestParserError::SyntaxError(1, uri.to_owned()))?;
let name = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let name = name
.map_err(|_| RequestParserError::SyntaxError(1, name.to_owned()))?;
debug_assert!(parts.next().is_none());
Ok((Request::StickerGet(sticker_type, uri, name), ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> {
let parts: Vec<_> = parts.into();
let mut parts = parts.into_iter().peekable();
let (key, sticker) = get_next_property!(parts, Text);
debug_assert!(parts.peek().is_none());
debug_assert!(key == "sticker");
Ok(sticker.to_string())