Files
empidee/src/commands/queue/moveid.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

63 lines
1.7 KiB
Rust

use serde::{Deserialize, Serialize};
use crate::{
commands::{Command, CommandRequest, RequestParserError, empty_command_response},
request_tokenizer::RequestTokenizer,
types::{AbsouluteRelativeSongPosition, SongId},
};
pub struct MoveId;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MoveIdRequest {
pub id: SongId,
pub to: AbsouluteRelativeSongPosition,
}
impl MoveIdRequest {
pub fn new(id: SongId, to: AbsouluteRelativeSongPosition) -> Self {
Self { id, to }
}
}
impl CommandRequest for MoveIdRequest {
const COMMAND: &'static str = "moveid";
const MIN_ARGS: u32 = 2;
const MAX_ARGS: Option<u32> = Some(2);
fn serialize(&self) -> String {
format!("{} {} {}\n", Self::COMMAND, self.id, self.to)
}
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
let id = parts.next().ok_or(Self::missing_arguments_error(0))?;
let id = id
.parse()
.map_err(|_| RequestParserError::SubtypeParserError {
argument_index: 0,
expected_type: "SongId",
raw_input: id.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(MoveIdRequest { id, to })
}
}
empty_command_response!(MoveId);
impl Command for MoveId {
type Request = MoveIdRequest;
type Response = MoveIdResponse;
}