Files
empidee/src/commands/queue/move_.rs

52 lines
1.5 KiB
Rust

use serde::{Deserialize, Serialize};
use crate::{
Request,
request_tokenizer::RequestTokenizer,
commands::{
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
},
common::{AbsouluteRelativeSongPosition, OneOrRange},
};
pub struct Move;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MoveRequest {
pub from_or_range: OneOrRange,
pub to: AbsouluteRelativeSongPosition,
}
impl Command for Move {
type Request = MoveRequest;
type Response = ();
const COMMAND: &'static str = "move";
fn serialize_request(&self, request: Self::Request) -> String {
format!("{} {} {}", Self::COMMAND, request.from_or_range, request.to)
}
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
let from_or_range = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let from_or_range = from_or_range
.parse()
.map_err(|_| RequestParserError::SyntaxError(0, from_or_range.to_string()))?;
let to = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let to = to
.parse()
.map_err(|_| RequestParserError::SyntaxError(0, to.to_string()))?;
debug_assert!(parts.next().is_none());
Ok((Request::Move(from_or_range, to), ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError<'_>> {
debug_assert!(parts.is_empty());
Ok(())
}
}