Files
empidee/src/commands/queue/rangeid.rs
T
oysteikt 56d7c942db commands: remove toplevel Request/Response enums
This also exposes all the command types as public API
2026-06-21 15:39:23 +09:00

70 lines
1.9 KiB
Rust

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