Lines
0 %
Functions
use serde::{Deserialize, Serialize};
use crate::{
commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError},
request_tokenizer::RequestTokenizer,
response_tokenizer::ResponseAttributes,
types::{PlaylistVersion, SongId, SongPosition, WindowRange},
};
pub struct PlChangesPosId;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlChangesPosIdRequest {
pub version: PlaylistVersion,
pub window: Option<WindowRange>,
}
impl PlChangesPosIdRequest {
pub fn new(version: PlaylistVersion, window: Option<WindowRange>) -> Self {
Self { version, window }
impl CommandRequest for PlChangesPosIdRequest {
const COMMAND: &'static str = "plchangesposid";
const MIN_ARGS: u32 = 1;
const MAX_ARGS: Option<u32> = Some(2);
fn into_request_enum(self) -> crate::Request {
crate::Request::PlChangesPosId(self.version, self.window)
fn from_request_enum(request: crate::Request) -> Option<Self> {
match request {
crate::Request::PlChangesPosId(version, window) => {
Some(PlChangesPosIdRequest { version, window })
_ => None,
fn serialize(&self) -> String {
match self.window.as_ref() {
Some(window) => format!("{} {} {}\n", Self::COMMAND, self.version, window),
None => format!("{} {}\n", Self::COMMAND, self.version),
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
let version = parts.next().ok_or(Self::missing_arguments_error(0))?;
let version = version
.parse()
.map_err(|_| RequestParserError::SubtypeParserError {
argument_index: 0,
expected_type: "PlaylistVersion",
raw_input: version.to_string(),
})?;
let window = parts
.next()
.map(|w| {
w.parse()
argument_index: 1,
expected_type: "WindowRange",
raw_input: w.to_string(),
})
.transpose()?;
Self::throw_if_too_many_arguments(parts)?;
Ok(PlChangesPosIdRequest { version, window })
pub struct PlChangesPosIdResponse(Vec<PlChangesPosIdResponseEntry>);
impl PlChangesPosIdResponse {
pub fn new(items: Vec<PlChangesPosIdResponseEntry>) -> Self {
PlChangesPosIdResponse(items)
pub struct PlChangesPosIdResponseEntry {
// 'cpos'
pub position: SongPosition,
pub id: SongId,
impl PlChangesPosIdResponseEntry {
pub fn new(position: SongPosition, id: SongId) -> Self {
PlChangesPosIdResponseEntry { position, id }
impl CommandResponse for PlChangesPosIdResponse {
fn from_response_enum(_response: crate::Response) -> Option<Self> {
todo!()
fn into_response_enum(self) -> crate::Response {
fn parse(_parts: ResponseAttributes<'_>) -> Result<Self, ResponseParserError> {
unimplemented!()
impl Command for PlChangesPosId {
type Request = PlChangesPosIdRequest;
type Response = PlChangesPosIdResponse;