58 lines
1.6 KiB
Rust
58 lines
1.6 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";
|
|
|
|
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!("{} {} {}", Self::COMMAND, self.id, self.to)
|
|
}
|
|
|
|
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
|
|
let id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
|
let id = id
|
|
.parse()
|
|
.map_err(|_| RequestParserError::SyntaxError(0, id.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(MoveIdRequest { id, to })
|
|
}
|
|
}
|
|
|
|
empty_command_response!(MoveId);
|
|
|
|
impl Command<'_, '_> for MoveId {
|
|
type Request = MoveIdRequest;
|
|
type Response = MoveIdResponse;
|
|
}
|