68 lines
1.9 KiB
Rust
68 lines
1.9 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 CommandRequest for MoveIdRequest {
|
|
const COMMAND: &'static str = "moveid";
|
|
const MIN_ARGS: u32 = 2;
|
|
const MAX_ARGS: Option<u32> = Some(2);
|
|
|
|
fn into_request_enum(self) -> crate::Request {
|
|
crate::Request::MoveId(self.id, self.to)
|
|
}
|
|
|
|
fn from_request_enum(request: crate::Request) -> Option<Self> {
|
|
match request {
|
|
crate::Request::MoveId(id, to) => Some(MoveIdRequest { id, to }),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|