Lines
0 %
Functions
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 into_request_enum(self) -> crate::Request {
crate::Request::Move(self.from_or_range, self.to)
fn from_request_enum(request: crate::Request) -> Option<Self> {
match request {
crate::Request::Move(from_or_range, to) => Some(MoveRequest { from_or_range, to }),
_ => None,
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
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;