Files
empidee/src/commands/queue/move_.rs
T
oysteikt cf09865b02 commands: remove toplevel Request/Response enums
This also exposes all the command types as public API
2026-06-21 14:41:56 +09:00

64 lines
1.8 KiB
Rust

use serde::{Deserialize, Serialize};
use crate::{
commands::{Command, CommandRequest, RequestParserError, empty_command_response},
request_tokenizer::RequestTokenizer,
types::{AbsouluteRelativeSongPosition, OneOrRange},
};
pub struct Move;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MoveRequest {
pub from_or_range: OneOrRange,
pub to: AbsouluteRelativeSongPosition,
}
impl MoveRequest {
pub fn new(from_or_range: OneOrRange, to: AbsouluteRelativeSongPosition) -> Self {
Self { from_or_range, to }
}
}
impl CommandRequest for MoveRequest {
const COMMAND: &'static str = "move";
const MIN_ARGS: u32 = 2;
const MAX_ARGS: Option<u32> = Some(2);
fn serialize(&self) -> String {
format!("{} {} {}\n", Self::COMMAND, self.from_or_range, self.to)
}
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
let from_or_range = parts.next().ok_or(Self::missing_arguments_error(0))?;
let from_or_range =
from_or_range
.parse()
.map_err(|_| RequestParserError::SubtypeParserError {
argument_index: 0,
expected_type: "OneOrRange",
raw_input: from_or_range.to_string(),
})?;
let to = parts.next().ok_or(Self::missing_arguments_error(1))?;
let to = to
.parse()
.map_err(|_| RequestParserError::SubtypeParserError {
argument_index: 1,
expected_type: "AbsoluteRelativeSongPosition",
raw_input: to.to_string(),
})?;
Self::throw_if_too_many_arguments(parts)?;
Ok(MoveRequest { from_or_range, to })
}
}
empty_command_response!(Move);
impl Command for Move {
type Request = MoveRequest;
type Response = MoveResponse;
}