diff --git a/src/client.rs b/src/client.rs index ef06cd8..4ba49ea 100644 --- a/src/client.rs +++ b/src/client.rs @@ -106,9 +106,9 @@ where Ok(response) } - pub async fn execute(&mut self, request: C::Request) -> Result + pub async fn execute(&mut self, request: R) -> Result where - C: Command, + R: CommandRequest, { let payload = request.serialize(); @@ -123,7 +123,7 @@ where .map_err(MpdClientError::ConnectionError)?; let response_bytes = self.read_response().await?; - let response = C::Response::parse_raw(&response_bytes)?; + let response = R::Response::parse_raw(&response_bytes)?; Ok(response) } @@ -132,7 +132,6 @@ where &mut self, position: Option, ) -> Result { - let request = ::Request::new(position); - self.execute::(request).await + self.execute(PlayRequest::new(position)).await } } diff --git a/src/commands.rs b/src/commands.rs index 2251b73..75f079d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -2,10 +2,6 @@ //! //! An mpd command consists of a pair of serializers and parsers for both the request //! and the corresponding response, as well as the command name used to identify the command. -//! -//! Each command is modelled as a struct implementing the [`Command`] trait, -//! which in turn uses the [`CommandRequest`] and [`CommandResponse`] traits -//! to define the request and response types respectively. use crate::{request_tokenizer::RequestTokenizer, response_tokenizer::ResponseAttributes}; @@ -45,6 +41,9 @@ pub trait CommandRequest where Self: Sized, { + /// The response type produced by the server when this request is executed. + type Response: CommandResponse; + /// The command name used within the protocol const COMMAND: &'static str; @@ -133,8 +132,8 @@ pub trait CommandResponse where Self: Sized, { - // /// Serializes the response into a Vec. - // fn serialize(&self) -> Vec; + /// The request type that provokes this response. + type Request: CommandRequest; /// Parses the response from its tokenized parts. /// See also [`parse_raw`]. @@ -144,40 +143,11 @@ where fn parse_raw(raw: &[u8]) -> Result { Self::parse(ResponseAttributes::new_from_bytes(raw)) } -} -/// A trait modelling the request/response pair of a single MPD command. -pub trait Command { - /// The request sent from the client to the server - type Request: CommandRequest; - /// The response sent from the server to the client - type Response: CommandResponse; - - /// The command name used within the protocol - const COMMAND: &'static str = Self::Request::COMMAND; - - /// Parse the request from its tokenized parts. See also [`parse_raw_request`]. - fn parse_request(parts: RequestTokenizer) -> Result { - Self::Request::parse(parts) - } - - /// Parse the raw request string into a request. - /// This assumes the raw string starts with the command name, e.g. `command_name arg1 "arg2 arg3"` - fn parse_raw_request(raw: &str) -> Result { - Self::Request::parse_raw(raw) - } - - // /// Serialize the response into a string. - // fn serialize_response(&self, response: Self::Response) -> String { - - /// Parse the response from its tokenized parts. See also [`parse_raw_response`]. - fn parse_response(parts: ResponseAttributes) -> Result { - Self::Response::parse(parts) - } - /// Parse the raw response string into a response. - fn parse_raw_response(raw: &[u8]) -> Result { - Self::Response::parse_raw(raw) - } + /// Serializes the response to its raw byte representaion. + /// + /// Note that this does not include the trailing `OK\n` terminator. + fn serialize(&self) -> Vec; } // Request/response implementation helpers @@ -196,6 +166,8 @@ macro_rules! empty_command_request { } impl crate::commands::CommandRequest for paste::paste! { [<$name Request>] } { + type Response = paste::paste! { [<$name Response>] }; + const COMMAND: &'static str = $command_name; const MIN_ARGS: u32 = 0; const MAX_ARGS: Option = Some(0); @@ -229,12 +201,18 @@ macro_rules! empty_command_response { } impl crate::commands::CommandResponse for paste::paste! { [<$name Response>] } { + type Request = paste::paste! { [<$name Request>] }; + fn parse( _parts: crate::commands::ResponseAttributes<'_>, ) -> Result { debug_assert!(_parts.is_empty()); Ok(paste::paste! { [<$name Response>] }) } + + fn serialize(&self) -> Vec { + Vec::with_capacity(0) + } } }; } @@ -255,6 +233,8 @@ macro_rules! single_item_command_request { } impl crate::commands::CommandRequest for paste::paste! { [<$name Request>] } { + type Response = paste::paste! { [<$name Response>] }; + const COMMAND: &'static str = $command_name; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(1); @@ -300,6 +280,8 @@ macro_rules! single_optional_item_command_request { } impl crate::commands::CommandRequest for paste::paste! { [<$name Request>] } { + type Response = paste::paste! { [<$name Response>] }; + const COMMAND: &'static str = $command_name; const MIN_ARGS: u32 = 0; const MAX_ARGS: Option = Some(1); @@ -351,6 +333,8 @@ macro_rules! single_item_command_response { } impl crate::commands::CommandResponse for paste::paste! { [<$name Response>] } { + type Request = paste::paste! { [<$name Request>] }; + fn parse( parts: crate::commands::ResponseAttributes<'_>, ) -> Result { @@ -375,6 +359,15 @@ macro_rules! single_item_command_response { Ok(paste::paste! { [<$name Response>] ( item ) }) } + + fn serialize(&self) -> Vec { + paste::paste! { + unimplemented!(concat!( + "response serialization is not yet implemented for ", + stringify!([<$name Response>]) + )) + } + } } }; } @@ -395,6 +388,8 @@ macro_rules! multi_item_command_response { } impl crate::commands::CommandResponse for paste::paste! { [<$name Response>] } { + type Request = paste::paste! { [<$name Request>] }; + fn parse( parts: crate::commands::ResponseAttributes<'_>, ) -> Result { @@ -422,6 +417,15 @@ macro_rules! multi_item_command_response { Ok(paste::paste! { [<$name Response>] ( items ) }) } + + fn serialize(&self) -> Vec { + paste::paste! { + unimplemented!(concat!( + "response serialization is not yet implemented for ", + stringify!([<$name Response>]) + )) + } + } } }; } @@ -569,147 +573,147 @@ pub enum ResponseParserError { pub const COMMAND_NAMES: &[&str] = &[ // Audio output devices - DisableOutput::COMMAND, - EnableOutput::COMMAND, - Outputs::COMMAND, - OutputSet::COMMAND, - ToggleOutput::COMMAND, + DisableOutputRequest::COMMAND, + EnableOutputRequest::COMMAND, + OutputsRequest::COMMAND, + OutputSetRequest::COMMAND, + ToggleOutputRequest::COMMAND, // Client to client - Channels::COMMAND, - ReadMessages::COMMAND, - SendMessage::COMMAND, - Subscribe::COMMAND, - Unsubscribe::COMMAND, + ChannelsRequest::COMMAND, + ReadMessagesRequest::COMMAND, + SendMessageRequest::COMMAND, + SubscribeRequest::COMMAND, + UnsubscribeRequest::COMMAND, // Connection settings - BinaryLimit::COMMAND, - Close::COMMAND, - Kill::COMMAND, - Password::COMMAND, - Ping::COMMAND, - Protocol::COMMAND, - ProtocolAll::COMMAND, - ProtocolAvailable::COMMAND, - ProtocolClear::COMMAND, - ProtocolDisable::COMMAND, - ProtocolEnable::COMMAND, - TagTypes::COMMAND, - TagTypesAll::COMMAND, - TagTypesAvailable::COMMAND, - TagTypesClear::COMMAND, - TagTypesDisable::COMMAND, - TagTypesEnable::COMMAND, - TagTypesReset::COMMAND, + BinaryLimitRequest::COMMAND, + CloseRequest::COMMAND, + KillRequest::COMMAND, + PasswordRequest::COMMAND, + PingRequest::COMMAND, + ProtocolRequest::COMMAND, + ProtocolAllRequest::COMMAND, + ProtocolAvailableRequest::COMMAND, + ProtocolClearRequest::COMMAND, + ProtocolDisableRequest::COMMAND, + ProtocolEnableRequest::COMMAND, + TagTypesRequest::COMMAND, + TagTypesAllRequest::COMMAND, + TagTypesAvailableRequest::COMMAND, + TagTypesClearRequest::COMMAND, + TagTypesDisableRequest::COMMAND, + TagTypesEnableRequest::COMMAND, + TagTypesResetRequest::COMMAND, // Controlling playback - Next::COMMAND, - Pause::COMMAND, - Play::COMMAND, - PlayId::COMMAND, - Previous::COMMAND, - Seek::COMMAND, - SeekCur::COMMAND, - SeekId::COMMAND, - Stop::COMMAND, + NextRequest::COMMAND, + PauseRequest::COMMAND, + PlayRequest::COMMAND, + PlayIdRequest::COMMAND, + PreviousRequest::COMMAND, + SeekRequest::COMMAND, + SeekCurRequest::COMMAND, + SeekIdRequest::COMMAND, + StopRequest::COMMAND, // Mounts and neighbors - ListMounts::COMMAND, - ListNeighbors::COMMAND, - Mount::COMMAND, - Unmount::COMMAND, + ListMountsRequest::COMMAND, + ListNeighborsRequest::COMMAND, + MountRequest::COMMAND, + UnmountRequest::COMMAND, // Music database - AlbumArt::COMMAND, - Count::COMMAND, - Find::COMMAND, - FindAdd::COMMAND, - GetFingerprint::COMMAND, - List::COMMAND, - ListAll::COMMAND, - ListAllInfo::COMMAND, - ListFiles::COMMAND, - LsInfo::COMMAND, - ReadComments::COMMAND, - ReadPicture::COMMAND, - Rescan::COMMAND, - Search::COMMAND, - SearchAdd::COMMAND, - SearchAddPl::COMMAND, - SearchCount::COMMAND, - Update::COMMAND, + AlbumArtRequest::COMMAND, + CountRequest::COMMAND, + FindRequest::COMMAND, + FindAddRequest::COMMAND, + GetFingerprintRequest::COMMAND, + ListRequest::COMMAND, + ListAllRequest::COMMAND, + ListAllInfoRequest::COMMAND, + ListFilesRequest::COMMAND, + LsInfoRequest::COMMAND, + ReadCommentsRequest::COMMAND, + ReadPictureRequest::COMMAND, + RescanRequest::COMMAND, + SearchRequest::COMMAND, + SearchAddRequest::COMMAND, + SearchAddPlRequest::COMMAND, + SearchCountRequest::COMMAND, + UpdateRequest::COMMAND, // Partition commands - DelPartition::COMMAND, - ListPartitions::COMMAND, - MoveOutput::COMMAND, - NewPartition::COMMAND, - Partition::COMMAND, + DelPartitionRequest::COMMAND, + ListPartitionsRequest::COMMAND, + MoveOutputRequest::COMMAND, + NewPartitionRequest::COMMAND, + PartitionRequest::COMMAND, // Playback options - Consume::COMMAND, - Crossfade::COMMAND, - GetVol::COMMAND, - MixRampDb::COMMAND, - MixRampDelay::COMMAND, - Random::COMMAND, - Repeat::COMMAND, - ReplayGainMode::COMMAND, - ReplayGainStatus::COMMAND, - SetVol::COMMAND, - Single::COMMAND, - Volume::COMMAND, + ConsumeRequest::COMMAND, + CrossfadeRequest::COMMAND, + GetVolRequest::COMMAND, + MixRampDbRequest::COMMAND, + MixRampDelayRequest::COMMAND, + RandomRequest::COMMAND, + RepeatRequest::COMMAND, + ReplayGainModeRequest::COMMAND, + ReplayGainStatusRequest::COMMAND, + SetVolRequest::COMMAND, + SingleRequest::COMMAND, + VolumeRequest::COMMAND, // Querying mpd status - ClearError::COMMAND, - CurrentSong::COMMAND, - Idle::COMMAND, - Stats::COMMAND, - Status::COMMAND, + ClearErrorRequest::COMMAND, + CurrentSongRequest::COMMAND, + IdleRequest::COMMAND, + StatsRequest::COMMAND, + StatusRequest::COMMAND, // Queue - Add::COMMAND, - AddId::COMMAND, - AddTagId::COMMAND, - Clear::COMMAND, - ClearTagId::COMMAND, - Delete::COMMAND, - DeleteId::COMMAND, - Move::COMMAND, - MoveId::COMMAND, - Playlist::COMMAND, - PlaylistFind::COMMAND, - PlaylistId::COMMAND, - PlaylistInfo::COMMAND, - PlaylistSearch::COMMAND, - PlChanges::COMMAND, - PlChangesPosId::COMMAND, - Prio::COMMAND, - PrioId::COMMAND, - RangeId::COMMAND, - Shuffle::COMMAND, - Swap::COMMAND, - SwapId::COMMAND, + AddRequest::COMMAND, + AddIdRequest::COMMAND, + AddTagIdRequest::COMMAND, + ClearRequest::COMMAND, + ClearTagIdRequest::COMMAND, + DeleteRequest::COMMAND, + DeleteIdRequest::COMMAND, + MoveRequest::COMMAND, + MoveIdRequest::COMMAND, + PlaylistRequest::COMMAND, + PlaylistFindRequest::COMMAND, + PlaylistIdRequest::COMMAND, + PlaylistInfoRequest::COMMAND, + PlaylistSearchRequest::COMMAND, + PlChangesRequest::COMMAND, + PlChangesPosIdRequest::COMMAND, + PrioRequest::COMMAND, + PrioIdRequest::COMMAND, + RangeIdRequest::COMMAND, + ShuffleRequest::COMMAND, + SwapRequest::COMMAND, + SwapIdRequest::COMMAND, // Reflection - Commands::COMMAND, - Config::COMMAND, - Decoders::COMMAND, - NotCommands::COMMAND, - UrlHandlers::COMMAND, + CommandsRequest::COMMAND, + ConfigRequest::COMMAND, + DecodersRequest::COMMAND, + NotCommandsRequest::COMMAND, + UrlHandlersRequest::COMMAND, // Stickers - StickerDec::COMMAND, - StickerDelete::COMMAND, - StickerFind::COMMAND, - StickerGet::COMMAND, - StickerInc::COMMAND, - StickerList::COMMAND, - StickerSet::COMMAND, - StickerNames::COMMAND, - StickerNamesTypes::COMMAND, - StickerTypes::COMMAND, + StickerDecRequest::COMMAND, + StickerDeleteRequest::COMMAND, + StickerFindRequest::COMMAND, + StickerGetRequest::COMMAND, + StickerIncRequest::COMMAND, + StickerListRequest::COMMAND, + StickerSetRequest::COMMAND, + StickerNamesRequest::COMMAND, + StickerNamesTypesRequest::COMMAND, + StickerTypesRequest::COMMAND, // Stored playlists - ListPlaylist::COMMAND, - ListPlaylistInfo::COMMAND, - ListPlaylists::COMMAND, - Load::COMMAND, - PlaylistAdd::COMMAND, - PlaylistClear::COMMAND, - PlaylistDelete::COMMAND, - PlaylistLength::COMMAND, - PlaylistMove::COMMAND, - Rename::COMMAND, - Rm::COMMAND, - Save::COMMAND, - SearchPlaylist::COMMAND, + ListPlaylistRequest::COMMAND, + ListPlaylistInfoRequest::COMMAND, + ListPlaylistsRequest::COMMAND, + LoadRequest::COMMAND, + PlaylistAddRequest::COMMAND, + PlaylistClearRequest::COMMAND, + PlaylistDeleteRequest::COMMAND, + PlaylistLengthRequest::COMMAND, + PlaylistMoveRequest::COMMAND, + RenameRequest::COMMAND, + RmRequest::COMMAND, + SaveRequest::COMMAND, + SearchPlaylistRequest::COMMAND, ]; diff --git a/src/commands/audio_output_devices/disableoutput.rs b/src/commands/audio_output_devices/disableoutput.rs index d541904..ca576a4 100644 --- a/src/commands/audio_output_devices/disableoutput.rs +++ b/src/commands/audio_output_devices/disableoutput.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::AudioOutputId, }; -pub struct DisableOutput; - single_item_command_request!(DisableOutput, "disableoutput", AudioOutputId); empty_command_response!(DisableOutput); - -impl Command for DisableOutput { - type Request = DisableOutputRequest; - type Response = DisableOutputResponse; -} diff --git a/src/commands/audio_output_devices/enableoutput.rs b/src/commands/audio_output_devices/enableoutput.rs index 45d1453..97025d0 100644 --- a/src/commands/audio_output_devices/enableoutput.rs +++ b/src/commands/audio_output_devices/enableoutput.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::AudioOutputId, }; -pub struct EnableOutput; - single_item_command_request!(EnableOutput, "enableoutput", AudioOutputId); empty_command_response!(EnableOutput); - -impl Command for EnableOutput { - type Request = EnableOutputRequest; - type Response = EnableOutputResponse; -} diff --git a/src/commands/audio_output_devices/outputs.rs b/src/commands/audio_output_devices/outputs.rs index 9271c4d..d0ed9f5 100644 --- a/src/commands/audio_output_devices/outputs.rs +++ b/src/commands/audio_output_devices/outputs.rs @@ -3,13 +3,11 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, empty_command_request}, + commands::{CommandResponse, ResponseParserError, empty_command_request}, response_tokenizer::{ResponseAttributes, expect_property_type}, types::AudioOutputId, }; -pub struct Outputs; - empty_command_request!(Outputs, "outputs"); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -49,6 +47,8 @@ impl Output { } impl CommandResponse for OutputsResponse { + type Request = OutputsRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts = parts.into_vec()?; @@ -130,11 +130,10 @@ impl CommandResponse for OutputsResponse { Ok(OutputsResponse(outputs)) } -} -impl Command for Outputs { - type Request = OutputsRequest; - type Response = OutputsResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for OutputsResponse") + } } #[cfg(test)] @@ -157,7 +156,7 @@ mod tests { attribute: fifo_path=/tmp/empidee-visualizer.fifo OK "}; - let result = Outputs::parse_raw_response(input.as_bytes()); + let result = OutputsResponse::parse_raw(input.as_bytes()); assert_eq!( result, Ok(OutputsResponse(vec![ diff --git a/src/commands/audio_output_devices/outputset.rs b/src/commands/audio_output_devices/outputset.rs index b5d135a..678626d 100644 --- a/src/commands/audio_output_devices/outputset.rs +++ b/src/commands/audio_output_devices/outputset.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::AudioOutputId, }; -pub struct OutputSet; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct OutputSetRequest { pub output_id: AudioOutputId, @@ -26,6 +24,8 @@ impl OutputSetRequest { } impl CommandRequest for OutputSetRequest { + type Response = OutputSetResponse; + const COMMAND: &'static str = "outputset"; const MIN_ARGS: u32 = 3; const MAX_ARGS: Option = Some(3); @@ -63,8 +63,3 @@ impl CommandRequest for OutputSetRequest { } empty_command_response!(OutputSet); - -impl Command for OutputSet { - type Request = OutputSetRequest; - type Response = OutputSetResponse; -} diff --git a/src/commands/audio_output_devices/toggleoutput.rs b/src/commands/audio_output_devices/toggleoutput.rs index b82238f..1f673c2 100644 --- a/src/commands/audio_output_devices/toggleoutput.rs +++ b/src/commands/audio_output_devices/toggleoutput.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::AudioOutputId, }; -pub struct ToggleOutput; - single_item_command_request!(ToggleOutput, "toggleoutput", AudioOutputId); empty_command_response!(ToggleOutput); - -impl Command for ToggleOutput { - type Request = ToggleOutputRequest; - type Response = ToggleOutputResponse; -} diff --git a/src/commands/client_to_client/channels.rs b/src/commands/client_to_client/channels.rs index aaeb9be..5997d6f 100644 --- a/src/commands/client_to_client/channels.rs +++ b/src/commands/client_to_client/channels.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, empty_command_request}, + commands::{CommandResponse, ResponseParserError, empty_command_request}, response_tokenizer::{ResponseAttributes, expect_property_type}, types::ChannelName, }; -pub struct Channels; - empty_command_request!(Channels, "channels"); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -22,6 +20,8 @@ impl ChannelsResponse { } impl CommandResponse for ChannelsResponse { + type Request = ChannelsRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: Vec<_> = parts.into_vec()?; let mut channel_names = Vec::with_capacity(parts.len()); @@ -38,11 +38,10 @@ impl CommandResponse for ChannelsResponse { channels: channel_names, }) } -} -impl Command for Channels { - type Request = ChannelsRequest; - type Response = ChannelsResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for ChannelsResponse") + } } #[cfg(test)] @@ -59,7 +58,7 @@ mod tests { channels: baz OK "}; - let response = Channels::parse_raw_response(response.as_bytes()).unwrap(); + let response = ChannelsResponse::parse_raw(response.as_bytes()).unwrap(); assert_eq!( response, ChannelsResponse { diff --git a/src/commands/client_to_client/readmessages.rs b/src/commands/client_to_client/readmessages.rs index f304262..886b507 100644 --- a/src/commands/client_to_client/readmessages.rs +++ b/src/commands/client_to_client/readmessages.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, empty_command_request}, + commands::{CommandResponse, ResponseParserError, empty_command_request}, response_tokenizer::{ResponseAttributes, expect_property_type}, types::ChannelName, }; -pub struct ReadMessages; - empty_command_request!(ReadMessages, "readmessages"); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -32,6 +30,8 @@ impl ReadMessagesResponseEntry { } impl CommandResponse for ReadMessagesResponse { + type Request = ReadMessagesRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: Vec<_> = parts.into_vec()?; debug_assert!(parts.len() % 2 == 0); @@ -57,11 +57,10 @@ impl CommandResponse for ReadMessagesResponse { Ok(ReadMessagesResponse(messages)) } -} -impl Command for ReadMessages { - type Request = ReadMessagesRequest; - type Response = ReadMessagesResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for ReadMessagesResponse") + } } #[cfg(test)] @@ -79,7 +78,7 @@ mod tests { message: message2 OK "}; - let result = ReadMessages::parse_raw_response(input.as_bytes()); + let result = ReadMessagesResponse::parse_raw(input.as_bytes()); assert_eq!( result, Ok(ReadMessagesResponse(vec![ diff --git a/src/commands/client_to_client/sendmessage.rs b/src/commands/client_to_client/sendmessage.rs index 0642202..dd588bb 100644 --- a/src/commands/client_to_client/sendmessage.rs +++ b/src/commands/client_to_client/sendmessage.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::ChannelName, }; -pub struct SendMessage; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SendMessageRequest { pub channel: ChannelName, @@ -21,6 +19,8 @@ impl SendMessageRequest { } impl CommandRequest for SendMessageRequest { + type Response = SendMessageResponse; + const COMMAND: &'static str = "sendmessage"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = None; @@ -47,8 +47,3 @@ impl CommandRequest for SendMessageRequest { } empty_command_response!(SendMessage); - -impl Command for SendMessage { - type Request = SendMessageRequest; - type Response = SendMessageResponse; -} diff --git a/src/commands/client_to_client/subscribe.rs b/src/commands/client_to_client/subscribe.rs index 0e7f191..2242cb2 100644 --- a/src/commands/client_to_client/subscribe.rs +++ b/src/commands/client_to_client/subscribe.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::ChannelName, }; -pub struct Subscribe; - single_item_command_request!(Subscribe, "subscribe", ChannelName); empty_command_response!(Subscribe); - -impl Command for Subscribe { - type Request = SubscribeRequest; - type Response = SubscribeResponse; -} diff --git a/src/commands/client_to_client/unsubscribe.rs b/src/commands/client_to_client/unsubscribe.rs index ad7ec13..e94ba1b 100644 --- a/src/commands/client_to_client/unsubscribe.rs +++ b/src/commands/client_to_client/unsubscribe.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::ChannelName, }; -pub struct Unsubscribe; - single_item_command_request!(Unsubscribe, "unsubscribe", ChannelName); empty_command_response!(Unsubscribe); - -impl Command for Unsubscribe { - type Request = UnsubscribeRequest; - type Response = UnsubscribeResponse; -} diff --git a/src/commands/connection_settings/binary_limit.rs b/src/commands/connection_settings/binary_limit.rs index 3872a2b..8ba1473 100644 --- a/src/commands/connection_settings/binary_limit.rs +++ b/src/commands/connection_settings/binary_limit.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_response, single_item_command_request}; - -pub struct BinaryLimit; +use crate::commands::{empty_command_response, single_item_command_request}; single_item_command_request!(BinaryLimit, "binarylimit", u64); empty_command_response!(BinaryLimit); - -impl Command for BinaryLimit { - type Request = BinaryLimitRequest; - type Response = BinaryLimitResponse; -} diff --git a/src/commands/connection_settings/close.rs b/src/commands/connection_settings/close.rs index 3205b29..18a1887 100644 --- a/src/commands/connection_settings/close.rs +++ b/src/commands/connection_settings/close.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_request, empty_command_response}; - -pub struct Close; +use crate::commands::{empty_command_request, empty_command_response}; empty_command_request!(Close, "close"); empty_command_response!(Close); - -impl Command for Close { - type Request = CloseRequest; - type Response = CloseResponse; -} diff --git a/src/commands/connection_settings/kill.rs b/src/commands/connection_settings/kill.rs index d67f2a4..a6bf061 100644 --- a/src/commands/connection_settings/kill.rs +++ b/src/commands/connection_settings/kill.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_request, empty_command_response}; - -pub struct Kill; +use crate::commands::{empty_command_request, empty_command_response}; empty_command_request!(Kill, "kill"); empty_command_response!(Kill); - -impl Command for Kill { - type Request = KillRequest; - type Response = KillResponse; -} diff --git a/src/commands/connection_settings/password.rs b/src/commands/connection_settings/password.rs index 79fcece..ba69af8 100644 --- a/src/commands/connection_settings/password.rs +++ b/src/commands/connection_settings/password.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_response, single_item_command_request}; - -pub struct Password; +use crate::commands::{empty_command_response, single_item_command_request}; single_item_command_request!(Password, "password", String); empty_command_response!(Password); - -impl Command for Password { - type Request = PasswordRequest; - type Response = PasswordResponse; -} diff --git a/src/commands/connection_settings/ping.rs b/src/commands/connection_settings/ping.rs index 98c34db..6f46f71 100644 --- a/src/commands/connection_settings/ping.rs +++ b/src/commands/connection_settings/ping.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_request, empty_command_response}; - -pub struct Ping; +use crate::commands::{empty_command_request, empty_command_response}; empty_command_request!(Ping, "ping"); empty_command_response!(Ping); - -impl Command for Ping { - type Request = PingRequest; - type Response = PingResponse; -} diff --git a/src/commands/connection_settings/protocol.rs b/src/commands/connection_settings/protocol.rs index 46a115c..f544686 100644 --- a/src/commands/connection_settings/protocol.rs +++ b/src/commands/connection_settings/protocol.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, ResponseParserError, empty_command_request, multi_item_command_response}, + commands::{ResponseParserError, empty_command_request, multi_item_command_response}, response_tokenizer::expect_property_type, }; -pub struct Protocol; - empty_command_request!(Protocol, "protocol"); multi_item_command_response!(Protocol, "feature", String); - -impl Command for Protocol { - type Request = ProtocolRequest; - type Response = ProtocolResponse; -} diff --git a/src/commands/connection_settings/protocol_all.rs b/src/commands/connection_settings/protocol_all.rs index c47be8f..34bbc77 100644 --- a/src/commands/connection_settings/protocol_all.rs +++ b/src/commands/connection_settings/protocol_all.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_request, empty_command_response}; - -pub struct ProtocolAll; +use crate::commands::{empty_command_request, empty_command_response}; empty_command_request!(ProtocolAll, "protocol all"); empty_command_response!(ProtocolAll); - -impl Command for ProtocolAll { - type Request = ProtocolAllRequest; - type Response = ProtocolAllResponse; -} diff --git a/src/commands/connection_settings/protocol_available.rs b/src/commands/connection_settings/protocol_available.rs index d1e6e6b..f1728cd 100644 --- a/src/commands/connection_settings/protocol_available.rs +++ b/src/commands/connection_settings/protocol_available.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, ResponseParserError, empty_command_request, multi_item_command_response}, + commands::{ResponseParserError, empty_command_request, multi_item_command_response}, response_tokenizer::expect_property_type, }; -pub struct ProtocolAvailable; - empty_command_request!(ProtocolAvailable, "protocol available"); multi_item_command_response!(ProtocolAvailable, "feature", String); - -impl Command for ProtocolAvailable { - type Request = ProtocolAvailableRequest; - type Response = ProtocolAvailableResponse; -} diff --git a/src/commands/connection_settings/protocol_clear.rs b/src/commands/connection_settings/protocol_clear.rs index 8d339d2..1df6049 100644 --- a/src/commands/connection_settings/protocol_clear.rs +++ b/src/commands/connection_settings/protocol_clear.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_request, empty_command_response}; - -pub struct ProtocolClear; +use crate::commands::{empty_command_request, empty_command_response}; empty_command_request!(ProtocolClear, "protocol clear"); empty_command_response!(ProtocolClear); - -impl Command for ProtocolClear { - type Request = ProtocolClearRequest; - type Response = ProtocolClearResponse; -} diff --git a/src/commands/connection_settings/protocol_disable.rs b/src/commands/connection_settings/protocol_disable.rs index 8805653..fad4730 100644 --- a/src/commands/connection_settings/protocol_disable.rs +++ b/src/commands/connection_settings/protocol_disable.rs @@ -1,11 +1,9 @@ use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::Feature, }; -pub struct ProtocolDisable; - pub struct ProtocolDisableRequest(Vec); impl ProtocolDisableRequest { @@ -15,6 +13,8 @@ impl ProtocolDisableRequest { } impl CommandRequest for ProtocolDisableRequest { + type Response = ProtocolDisableResponse; + const COMMAND: &'static str = "protocol disable"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = None; @@ -52,8 +52,3 @@ impl CommandRequest for ProtocolDisableRequest { } empty_command_response!(ProtocolDisable); - -impl Command for ProtocolDisable { - type Request = ProtocolDisableRequest; - type Response = ProtocolDisableResponse; -} diff --git a/src/commands/connection_settings/protocol_enable.rs b/src/commands/connection_settings/protocol_enable.rs index cafe24b..f177617 100644 --- a/src/commands/connection_settings/protocol_enable.rs +++ b/src/commands/connection_settings/protocol_enable.rs @@ -1,11 +1,9 @@ use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::Feature, }; -pub struct ProtocolEnable; - pub struct ProtocolEnableRequest(Vec); impl ProtocolEnableRequest { @@ -15,6 +13,8 @@ impl ProtocolEnableRequest { } impl CommandRequest for ProtocolEnableRequest { + type Response = ProtocolEnableResponse; + const COMMAND: &'static str = "protocol enable"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = None; @@ -52,8 +52,3 @@ impl CommandRequest for ProtocolEnableRequest { } empty_command_response!(ProtocolEnable); - -impl Command for ProtocolEnable { - type Request = ProtocolEnableRequest; - type Response = ProtocolEnableResponse; -} diff --git a/src/commands/connection_settings/tag_types.rs b/src/commands/connection_settings/tag_types.rs index 7b7f47f..18f374f 100644 --- a/src/commands/connection_settings/tag_types.rs +++ b/src/commands/connection_settings/tag_types.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, ResponseParserError, empty_command_request, multi_item_command_response}, + commands::{ResponseParserError, empty_command_request, multi_item_command_response}, response_tokenizer::expect_property_type, }; -pub struct TagTypes; - empty_command_request!(TagTypes, "tagtypes"); multi_item_command_response!(TagTypes, "tagtype", String); - -impl Command for TagTypes { - type Request = TagTypesRequest; - type Response = TagTypesResponse; -} diff --git a/src/commands/connection_settings/tag_types_all.rs b/src/commands/connection_settings/tag_types_all.rs index 54deb98..93659f5 100644 --- a/src/commands/connection_settings/tag_types_all.rs +++ b/src/commands/connection_settings/tag_types_all.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_request, empty_command_response}; - -pub struct TagTypesAll; +use crate::commands::{empty_command_request, empty_command_response}; empty_command_request!(TagTypesAll, "tagtypes all"); empty_command_response!(TagTypesAll); - -impl Command for TagTypesAll { - type Request = TagTypesAllRequest; - type Response = TagTypesAllResponse; -} diff --git a/src/commands/connection_settings/tag_types_available.rs b/src/commands/connection_settings/tag_types_available.rs index f6ba853..33f8ac2 100644 --- a/src/commands/connection_settings/tag_types_available.rs +++ b/src/commands/connection_settings/tag_types_available.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, ResponseParserError, empty_command_request, multi_item_command_response}, + commands::{ResponseParserError, empty_command_request, multi_item_command_response}, response_tokenizer::expect_property_type, }; -pub struct TagTypesAvailable; - empty_command_request!(TagTypesAvailable, "tagtypes available"); multi_item_command_response!(TagTypesAvailable, "tagtype", String); - -impl Command for TagTypesAvailable { - type Request = TagTypesAvailableRequest; - type Response = TagTypesAvailableResponse; -} diff --git a/src/commands/connection_settings/tag_types_clear.rs b/src/commands/connection_settings/tag_types_clear.rs index 8fa92eb..53978cb 100644 --- a/src/commands/connection_settings/tag_types_clear.rs +++ b/src/commands/connection_settings/tag_types_clear.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_request, empty_command_response}; - -pub struct TagTypesClear; +use crate::commands::{empty_command_request, empty_command_response}; empty_command_request!(TagTypesClear, "tagtypes clear"); empty_command_response!(TagTypesClear); - -impl Command for TagTypesClear { - type Request = TagTypesClearRequest; - type Response = TagTypesClearResponse; -} diff --git a/src/commands/connection_settings/tag_types_disable.rs b/src/commands/connection_settings/tag_types_disable.rs index b4b5187..fc31181 100644 --- a/src/commands/connection_settings/tag_types_disable.rs +++ b/src/commands/connection_settings/tag_types_disable.rs @@ -1,11 +1,9 @@ use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::TagName, }; -pub struct TagTypesDisable; - pub struct TagTypesDisableRequest(Vec); impl TagTypesDisableRequest { @@ -15,6 +13,8 @@ impl TagTypesDisableRequest { } impl CommandRequest for TagTypesDisableRequest { + type Response = TagTypesDisableResponse; + const COMMAND: &'static str = "tagtypes disable"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = None; @@ -54,8 +54,3 @@ impl CommandRequest for TagTypesDisableRequest { } empty_command_response!(TagTypesDisable); - -impl Command for TagTypesDisable { - type Request = TagTypesDisableRequest; - type Response = TagTypesDisableResponse; -} diff --git a/src/commands/connection_settings/tag_types_enable.rs b/src/commands/connection_settings/tag_types_enable.rs index 6a34de8..7c67761 100644 --- a/src/commands/connection_settings/tag_types_enable.rs +++ b/src/commands/connection_settings/tag_types_enable.rs @@ -1,11 +1,9 @@ use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::TagName, }; -pub struct TagTypesEnable; - pub struct TagTypesEnableRequest(Vec); impl TagTypesEnableRequest { @@ -15,6 +13,8 @@ impl TagTypesEnableRequest { } impl CommandRequest for TagTypesEnableRequest { + type Response = TagTypesEnableResponse; + const COMMAND: &'static str = "tagtypes enable"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = None; @@ -54,8 +54,3 @@ impl CommandRequest for TagTypesEnableRequest { } empty_command_response!(TagTypesEnable); - -impl Command for TagTypesEnable { - type Request = TagTypesEnableRequest; - type Response = TagTypesEnableResponse; -} diff --git a/src/commands/connection_settings/tag_types_reset.rs b/src/commands/connection_settings/tag_types_reset.rs index 8fbbdcf..20e3101 100644 --- a/src/commands/connection_settings/tag_types_reset.rs +++ b/src/commands/connection_settings/tag_types_reset.rs @@ -1,11 +1,9 @@ use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::TagName, }; -pub struct TagTypesReset; - pub struct TagTypesResetRequest(Vec); impl TagTypesResetRequest { @@ -15,6 +13,8 @@ impl TagTypesResetRequest { } impl CommandRequest for TagTypesResetRequest { + type Response = TagTypesResetResponse; + const COMMAND: &'static str = "tagtypes reset"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = None; @@ -54,8 +54,3 @@ impl CommandRequest for TagTypesResetRequest { } empty_command_response!(TagTypesReset); - -impl Command for TagTypesReset { - type Request = TagTypesResetRequest; - type Response = TagTypesResetResponse; -} diff --git a/src/commands/controlling_playback/next.rs b/src/commands/controlling_playback/next.rs index 6f8974b..974d3fa 100644 --- a/src/commands/controlling_playback/next.rs +++ b/src/commands/controlling_playback/next.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_request, empty_command_response}; - -pub struct Next; +use crate::commands::{empty_command_request, empty_command_response}; empty_command_request!(Next, "next"); empty_command_response!(Next); - -impl Command for Next { - type Request = NextRequest; - type Response = NextResponse; -} diff --git a/src/commands/controlling_playback/pause.rs b/src/commands/controlling_playback/pause.rs index f0d495c..de1bf7f 100644 --- a/src/commands/controlling_playback/pause.rs +++ b/src/commands/controlling_playback/pause.rs @@ -1,10 +1,8 @@ use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, }; -pub struct Pause; - pub struct PauseRequest(Option); impl PauseRequest { @@ -14,6 +12,8 @@ impl PauseRequest { } impl CommandRequest for PauseRequest { + type Response = PauseResponse; + const COMMAND: &'static str = "pause"; const MIN_ARGS: u32 = 0; const MAX_ARGS: Option = Some(1); @@ -45,8 +45,3 @@ impl CommandRequest for PauseRequest { } empty_command_response!(Pause); - -impl Command for Pause { - type Request = PauseRequest; - type Response = PauseResponse; -} diff --git a/src/commands/controlling_playback/play.rs b/src/commands/controlling_playback/play.rs index 56ee5e5..e9284bb 100644 --- a/src/commands/controlling_playback/play.rs +++ b/src/commands/controlling_playback/play.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_optional_item_command_request}, + commands::{empty_command_response, single_optional_item_command_request}, types::SongPosition, }; -pub struct Play; - single_optional_item_command_request!(Play, "play", SongPosition); empty_command_response!(Play); - -impl Command for Play { - type Request = PlayRequest; - type Response = PlayResponse; -} diff --git a/src/commands/controlling_playback/playid.rs b/src/commands/controlling_playback/playid.rs index b325fb0..fddbf7a 100644 --- a/src/commands/controlling_playback/playid.rs +++ b/src/commands/controlling_playback/playid.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_optional_item_command_request}, + commands::{empty_command_response, single_optional_item_command_request}, types::SongId, }; -pub struct PlayId; - single_optional_item_command_request!(PlayId, "playid", SongId); empty_command_response!(PlayId); - -impl Command for PlayId { - type Request = PlayIdRequest; - type Response = PlayIdResponse; -} diff --git a/src/commands/controlling_playback/previous.rs b/src/commands/controlling_playback/previous.rs index c2065dd..914f70b 100644 --- a/src/commands/controlling_playback/previous.rs +++ b/src/commands/controlling_playback/previous.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_request, empty_command_response}; - -pub struct Previous; +use crate::commands::{empty_command_request, empty_command_response}; empty_command_request!(Previous, "previous"); empty_command_response!(Previous); - -impl Command for Previous { - type Request = PreviousRequest; - type Response = PreviousResponse; -} diff --git a/src/commands/controlling_playback/seek.rs b/src/commands/controlling_playback/seek.rs index 9daa00b..dc8cbb0 100644 --- a/src/commands/controlling_playback/seek.rs +++ b/src/commands/controlling_playback/seek.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{SongPosition, TimeWithFractions}, }; -pub struct Seek; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SeekRequest { pub songpos: SongPosition, @@ -21,6 +19,8 @@ impl SeekRequest { } impl CommandRequest for SeekRequest { + type Response = SeekResponse; + const COMMAND: &'static str = "seek"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -61,8 +61,3 @@ impl CommandRequest for SeekRequest { } empty_command_response!(Seek); - -impl Command for Seek { - type Request = SeekRequest; - type Response = SeekResponse; -} diff --git a/src/commands/controlling_playback/seekcur.rs b/src/commands/controlling_playback/seekcur.rs index b2c72d8..10d32e3 100644 --- a/src/commands/controlling_playback/seekcur.rs +++ b/src/commands/controlling_playback/seekcur.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{SeekMode, TimeWithFractions}, }; -pub struct SeekCur; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SeekCurRequest { pub mode: SeekMode, @@ -21,6 +19,8 @@ impl SeekCurRequest { } impl CommandRequest for SeekCurRequest { + type Response = SeekCurResponse; + const COMMAND: &'static str = "seekcur"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(1); @@ -84,8 +84,3 @@ impl CommandRequest for SeekCurRequest { } empty_command_response!(SeekCur); - -impl Command for SeekCur { - type Request = SeekCurRequest; - type Response = SeekCurResponse; -} diff --git a/src/commands/controlling_playback/seekid.rs b/src/commands/controlling_playback/seekid.rs index c21575c..b3ce4cb 100644 --- a/src/commands/controlling_playback/seekid.rs +++ b/src/commands/controlling_playback/seekid.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{SongId, TimeWithFractions}, }; -pub struct SeekId; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SeekIdRequest { pub songid: SongId, @@ -21,6 +19,8 @@ impl SeekIdRequest { } impl CommandRequest for SeekIdRequest { + type Response = SeekIdResponse; + const COMMAND: &'static str = "seekid"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -59,8 +59,3 @@ impl CommandRequest for SeekIdRequest { } empty_command_response!(SeekId); - -impl Command for SeekId { - type Request = SeekIdRequest; - type Response = SeekIdResponse; -} diff --git a/src/commands/controlling_playback/stop.rs b/src/commands/controlling_playback/stop.rs index 2467f01..2af6e66 100644 --- a/src/commands/controlling_playback/stop.rs +++ b/src/commands/controlling_playback/stop.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_request, empty_command_response}; - -pub struct Stop; +use crate::commands::{empty_command_request, empty_command_response}; empty_command_request!(Stop, "stop"); empty_command_response!(Stop); - -impl Command for Stop { - type Request = StopRequest; - type Response = StopResponse; -} diff --git a/src/commands/mounts_and_neighbors/listmounts.rs b/src/commands/mounts_and_neighbors/listmounts.rs index 708c592..daed1af 100644 --- a/src/commands/mounts_and_neighbors/listmounts.rs +++ b/src/commands/mounts_and_neighbors/listmounts.rs @@ -1,24 +1,18 @@ use crate::{ - commands::{Command, ResponseParserError, empty_command_request, multi_item_command_response}, + commands::{ResponseParserError, empty_command_request, multi_item_command_response}, response_tokenizer::expect_property_type, }; -pub struct ListMounts; - empty_command_request!(ListMounts, "listmounts"); multi_item_command_response!(ListMounts, "mount", String); -impl Command for ListMounts { - type Request = ListMountsRequest; - type Response = ListMountsResponse; -} - #[cfg(test)] mod tests { use indoc::indoc; use super::*; + use crate::commands::CommandResponse; #[test] fn test_parse_response() { @@ -27,7 +21,7 @@ mod tests { mount: /mnt/music OK "}; - let result = ListMounts::parse_raw_response(input.as_bytes()); + let result = ListMountsResponse::parse_raw(input.as_bytes()); assert_eq!( result, Ok(ListMountsResponse(vec![ diff --git a/src/commands/mounts_and_neighbors/listneighbors.rs b/src/commands/mounts_and_neighbors/listneighbors.rs index 6cc7781..8276328 100644 --- a/src/commands/mounts_and_neighbors/listneighbors.rs +++ b/src/commands/mounts_and_neighbors/listneighbors.rs @@ -3,12 +3,10 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, empty_command_request}, + commands::{CommandResponse, ResponseParserError, empty_command_request}, response_tokenizer::{ResponseAttributes, expect_property_type}, }; -pub struct ListNeighbors; - empty_command_request!(ListNeighbors, "listneighbors"); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -21,6 +19,8 @@ impl ListNeighborsResponse { } impl CommandResponse for ListNeighborsResponse { + type Request = ListNeighborsRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: Vec<_> = parts.into_vec()?; debug_assert!(parts.len() % 2 == 0); @@ -42,9 +42,8 @@ impl CommandResponse for ListNeighborsResponse { Ok(ListNeighborsResponse(result)) } -} -impl Command for ListNeighbors { - type Request = ListNeighborsRequest; - type Response = ListNeighborsResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for ListNeighborsResponse") + } } diff --git a/src/commands/mounts_and_neighbors/mount.rs b/src/commands/mounts_and_neighbors/mount.rs index 735cd9f..3a98082 100644 --- a/src/commands/mounts_and_neighbors/mount.rs +++ b/src/commands/mounts_and_neighbors/mount.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{MountPath, Uri}, }; -pub struct Mount; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct MountRequest { pub path: MountPath, @@ -21,6 +19,8 @@ impl MountRequest { } impl CommandRequest for MountRequest { + type Response = MountResponse; + const COMMAND: &'static str = "mount"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -57,8 +57,3 @@ impl CommandRequest for MountRequest { } empty_command_response!(Mount); - -impl Command for Mount { - type Request = MountRequest; - type Response = MountResponse; -} diff --git a/src/commands/mounts_and_neighbors/unmount.rs b/src/commands/mounts_and_neighbors/unmount.rs index 26b30fd..29f075c 100644 --- a/src/commands/mounts_and_neighbors/unmount.rs +++ b/src/commands/mounts_and_neighbors/unmount.rs @@ -1,12 +1,8 @@ use crate::{ - commands::{ - Command, CommandRequest, RequestParserError, RequestTokenizer, empty_command_response, - }, + commands::{CommandRequest, RequestParserError, RequestTokenizer, empty_command_response}, types::MountPath, }; -pub struct Unmount; - #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct UnmountRequest(MountPath); @@ -17,6 +13,8 @@ impl UnmountRequest { } impl CommandRequest for UnmountRequest { + type Response = UnmountResponse; + const COMMAND: &'static str = "unmount"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(1); @@ -47,8 +45,3 @@ impl CommandRequest for UnmountRequest { } empty_command_response!(Unmount); - -impl Command for Unmount { - type Request = UnmountRequest; - type Response = UnmountResponse; -} diff --git a/src/commands/music_database/albumart.rs b/src/commands/music_database/albumart.rs index 9bb58a6..89c4939 100644 --- a/src/commands/music_database/albumart.rs +++ b/src/commands/music_database/albumart.rs @@ -3,14 +3,12 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, request_tokenizer::RequestTokenizer, response_tokenizer::{ResponseAttributes, get_and_parse_property, get_property}, types::{Offset, Uri}, }; -pub struct AlbumArt; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct AlbumArtRequest { uri: Uri, @@ -24,6 +22,8 @@ impl AlbumArtRequest { } impl CommandRequest for AlbumArtRequest { + type Response = AlbumArtResponse; + const COMMAND: &'static str = "albumart"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -71,6 +71,8 @@ impl AlbumArtResponse { } impl CommandResponse for AlbumArtResponse { + type Request = AlbumArtRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: HashMap<_, _> = parts.into_map()?; @@ -80,9 +82,8 @@ impl CommandResponse for AlbumArtResponse { Ok(AlbumArtResponse { size, binary }) } -} -impl Command for AlbumArt { - type Request = AlbumArtRequest; - type Response = AlbumArtResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for AlbumArtResponse") + } } diff --git a/src/commands/music_database/count.rs b/src/commands/music_database/count.rs index 7fb0233..fc3a5c6 100644 --- a/src/commands/music_database/count.rs +++ b/src/commands/music_database/count.rs @@ -3,15 +3,13 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, filter::Filter, request_tokenizer::RequestTokenizer, response_tokenizer::{ResponseAttributes, get_and_parse_property}, types::GroupType, }; -pub struct Count; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct CountRequest { filter: Filter, @@ -25,6 +23,8 @@ impl CountRequest { } impl CommandRequest for CountRequest { + type Response = CountResponse; + const COMMAND: &'static str = "count"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(2); @@ -86,6 +86,8 @@ impl CountResponse { } impl CommandResponse for CountResponse { + type Request = CountRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: HashMap<_, _> = parts.into_map()?; @@ -94,9 +96,8 @@ impl CommandResponse for CountResponse { Ok(CountResponse { songs, playtime }) } -} -impl Command for Count { - type Request = CountRequest; - type Response = CountResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for CountResponse") + } } diff --git a/src/commands/music_database/find.rs b/src/commands/music_database/find.rs index 29b6cec..d9a612e 100644 --- a/src/commands/music_database/find.rs +++ b/src/commands/music_database/find.rs @@ -1,15 +1,13 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, filter::Filter, request_tokenizer::RequestTokenizer, response_tokenizer::ResponseAttributes, types::{DbSelectionPrintResponse, DbSongInfo, Sort, WindowRange}, }; -pub struct Find; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct FindRequest { filter: Filter, @@ -28,6 +26,8 @@ impl FindRequest { } impl CommandRequest for FindRequest { + type Response = FindResponse; + const COMMAND: &'static str = "find"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(3); @@ -113,6 +113,8 @@ impl FindResponse { } impl CommandResponse for FindResponse { + type Request = FindRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { DbSelectionPrintResponse::parse(parts)? .into_iter() @@ -128,9 +130,8 @@ impl CommandResponse for FindResponse { .collect::, ResponseParserError>>() .map(FindResponse) } -} -impl Command for Find { - type Request = FindRequest; - type Response = FindResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for FindResponse") + } } diff --git a/src/commands/music_database/findadd.rs b/src/commands/music_database/findadd.rs index 709ba7b..b87f8b5 100644 --- a/src/commands/music_database/findadd.rs +++ b/src/commands/music_database/findadd.rs @@ -1,14 +1,12 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, filter::Filter, request_tokenizer::RequestTokenizer, types::{SongPosition, Sort, WindowRange}, }; -pub struct FindAdd; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct FindAddRequest { filter: Filter, @@ -34,6 +32,8 @@ impl FindAddRequest { } impl CommandRequest for FindAddRequest { + type Response = FindAddResponse; + const COMMAND: &'static str = "findadd"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(4); @@ -134,8 +134,3 @@ impl CommandRequest for FindAddRequest { } empty_command_response!(FindAdd); - -impl Command for FindAdd { - type Request = FindAddRequest; - type Response = FindAddResponse; -} diff --git a/src/commands/music_database/getfingerprint.rs b/src/commands/music_database/getfingerprint.rs index aa8a63d..274f5ec 100644 --- a/src/commands/music_database/getfingerprint.rs +++ b/src/commands/music_database/getfingerprint.rs @@ -3,13 +3,11 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, single_item_command_request}, + commands::{CommandResponse, ResponseParserError, single_item_command_request}, response_tokenizer::{ResponseAttributes, get_and_parse_property}, types::Uri, }; -pub struct GetFingerprint; - single_item_command_request!(GetFingerprint, "getfingerprint", Uri); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -24,6 +22,8 @@ impl GetFingerprintResponse { } impl CommandResponse for GetFingerprintResponse { + type Request = GetFingerprintRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: HashMap<_, _> = parts.into_map()?; @@ -31,9 +31,8 @@ impl CommandResponse for GetFingerprintResponse { Ok(GetFingerprintResponse { chromaprint }) } -} -impl Command for GetFingerprint { - type Request = GetFingerprintRequest; - type Response = GetFingerprintResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for GetFingerprintResponse") + } } diff --git a/src/commands/music_database/list.rs b/src/commands/music_database/list.rs index 0c04a91..bea8fad 100644 --- a/src/commands/music_database/list.rs +++ b/src/commands/music_database/list.rs @@ -1,15 +1,13 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, filter::Filter, request_tokenizer::RequestTokenizer, response_tokenizer::{ResponseAttributes, expect_property_type}, types::{GroupType, TagName, WindowRange}, }; -pub struct List; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ListRequest { tagname: TagName, @@ -35,6 +33,8 @@ impl ListRequest { } impl CommandRequest for ListRequest { + type Response = ListResponse; + const COMMAND: &'static str = "list"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = None; @@ -145,6 +145,8 @@ impl ListResponse { } impl CommandResponse for ListResponse { + type Request = ListRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts_: Vec<_> = parts.into_vec()?; debug_assert!({ @@ -159,9 +161,8 @@ impl CommandResponse for ListResponse { Ok(ListResponse(list)) } -} -impl Command for List { - type Request = ListRequest; - type Response = ListResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for ListResponse") + } } diff --git a/src/commands/music_database/listall.rs b/src/commands/music_database/listall.rs index 063f627..56fd423 100644 --- a/src/commands/music_database/listall.rs +++ b/src/commands/music_database/listall.rs @@ -1,15 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{ - Command, CommandResponse, ResponseParserError, single_optional_item_command_request, - }, + commands::{CommandResponse, ResponseParserError, single_optional_item_command_request}, response_tokenizer::ResponseAttributes, types::{DbSelectionPrintResponse, Uri}, }; -pub struct ListAll; - single_optional_item_command_request!(ListAll, "listall", Uri); // TODO: This is supposed to be a tree-like structure, with directories containing files and playlists @@ -23,16 +19,17 @@ impl ListAllResponse { } impl CommandResponse for ListAllResponse { + type Request = ListAllRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let result = DbSelectionPrintResponse::parse(parts)?; Ok(ListAllResponse(result)) } -} -impl Command for ListAll { - type Request = ListAllRequest; - type Response = ListAllResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for ListAllResponse") + } } #[cfg(test)] @@ -64,7 +61,7 @@ mod tests { OK "}; - let result = ListAll::parse_raw_response(response.as_bytes()); + let result = ListAllResponse::parse_raw(response.as_bytes()); assert_eq!( result, diff --git a/src/commands/music_database/listallinfo.rs b/src/commands/music_database/listallinfo.rs index 62ed533..80e3e47 100644 --- a/src/commands/music_database/listallinfo.rs +++ b/src/commands/music_database/listallinfo.rs @@ -1,15 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{ - Command, CommandResponse, ResponseParserError, single_optional_item_command_request, - }, + commands::{CommandResponse, ResponseParserError, single_optional_item_command_request}, response_tokenizer::ResponseAttributes, types::{DbSelectionPrintResponse, Uri}, }; -pub struct ListAllInfo; - single_optional_item_command_request!(ListAllInfo, "listallinfo", Uri); // TODO: This is supposed to be a tree-like structure, with directories containing files and playlists @@ -23,16 +19,17 @@ impl ListAllInfoResponse { } impl CommandResponse for ListAllInfoResponse { + type Request = ListAllInfoRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let result = DbSelectionPrintResponse::parse(parts)?; Ok(ListAllInfoResponse(result)) } -} -impl Command for ListAllInfo { - type Request = ListAllInfoRequest; - type Response = ListAllInfoResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for ListAllInfoResponse") + } } #[cfg(test)] @@ -74,7 +71,7 @@ mod tests { OK "}; - let result = ListAllInfo::parse_raw_response(response.as_bytes()); + let result = ListAllInfoResponse::parse_raw(response.as_bytes()); assert_eq!( result, diff --git a/src/commands/music_database/listfiles.rs b/src/commands/music_database/listfiles.rs index 00fcc08..96563c6 100644 --- a/src/commands/music_database/listfiles.rs +++ b/src/commands/music_database/listfiles.rs @@ -1,15 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{ - Command, CommandResponse, ResponseParserError, single_optional_item_command_request, - }, + commands::{CommandResponse, ResponseParserError, single_optional_item_command_request}, response_tokenizer::ResponseAttributes, types::{DbDirectoryInfo, DbSelectionPrintResponse, Uri}, }; -pub struct ListFiles; - single_optional_item_command_request!(ListFiles, "listfiles", Uri); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -22,6 +18,8 @@ impl ListFilesResponse { } impl CommandResponse for ListFilesResponse { + type Request = ListFilesRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { DbSelectionPrintResponse::parse(parts)? .into_iter() @@ -37,9 +35,8 @@ impl CommandResponse for ListFilesResponse { .collect::, ResponseParserError>>() .map(ListFilesResponse) } -} -impl Command for ListFiles { - type Request = ListFilesRequest; - type Response = ListFilesResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for ListFilesResponse") + } } diff --git a/src/commands/music_database/lsinfo.rs b/src/commands/music_database/lsinfo.rs index 5f883eb..ccf46cb 100644 --- a/src/commands/music_database/lsinfo.rs +++ b/src/commands/music_database/lsinfo.rs @@ -1,15 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{ - Command, CommandResponse, ResponseParserError, single_optional_item_command_request, - }, + commands::{CommandResponse, ResponseParserError, single_optional_item_command_request}, response_tokenizer::ResponseAttributes, types::{DbSelectionPrintResponse, Uri}, }; -pub struct LsInfo; - single_optional_item_command_request!(LsInfo, "lsinfo", Uri); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -22,16 +18,17 @@ impl LsInfoResponse { } impl CommandResponse for LsInfoResponse { + type Request = LsInfoRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let result = DbSelectionPrintResponse::parse(parts)?; Ok(LsInfoResponse(result)) } -} -impl Command for LsInfo { - type Request = LsInfoRequest; - type Response = LsInfoResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for LsInfoResponse") + } } #[cfg(test)] @@ -62,7 +59,7 @@ mod tests { OK "}; - let result = LsInfo::parse_raw_response(response.as_bytes()); + let result = LsInfoResponse::parse_raw(response.as_bytes()); assert_eq!( result, diff --git a/src/commands/music_database/readcomments.rs b/src/commands/music_database/readcomments.rs index 7b2ea53..db2306f 100644 --- a/src/commands/music_database/readcomments.rs +++ b/src/commands/music_database/readcomments.rs @@ -3,13 +3,11 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, single_item_command_request}, + commands::{CommandResponse, ResponseParserError, single_item_command_request}, response_tokenizer::{GenericResponseValue, ResponseAttributes}, types::Uri, }; -pub struct ReadComments; - single_item_command_request!(ReadComments, "readcomments", Uri); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -22,6 +20,8 @@ impl ReadCommentsResponse { } impl CommandResponse for ReadCommentsResponse { + type Request = ReadCommentsRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: HashMap<_, _> = parts.into_map()?; @@ -37,9 +37,8 @@ impl CommandResponse for ReadCommentsResponse { Ok(ReadCommentsResponse(comments)) } -} -impl Command for ReadComments { - type Request = ReadCommentsRequest; - type Response = ReadCommentsResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for ReadCommentsResponse") + } } diff --git a/src/commands/music_database/readpicture.rs b/src/commands/music_database/readpicture.rs index f207184..c3539cb 100644 --- a/src/commands/music_database/readpicture.rs +++ b/src/commands/music_database/readpicture.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, request_tokenizer::RequestTokenizer, response_tokenizer::{ ResponseAttributes, get_and_parse_property, get_optional_property, get_property, @@ -11,8 +11,6 @@ use crate::{ types::{Offset, Uri}, }; -pub struct ReadPicture; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ReadPictureRequest { pub uri: Uri, @@ -26,6 +24,8 @@ impl ReadPictureRequest { } impl CommandRequest for ReadPictureRequest { + type Response = ReadPictureResponse; + const COMMAND: &'static str = "readpicture"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -78,6 +78,8 @@ impl ReadPictureResponse { } impl CommandResponse for ReadPictureResponse { + type Request = ReadPictureRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: HashMap<_, _> = parts.into_map()?; @@ -98,9 +100,8 @@ impl CommandResponse for ReadPictureResponse { mimetype, }) } -} -impl Command for ReadPicture { - type Request = ReadPictureRequest; - type Response = ReadPictureResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for ReadPictureResponse") + } } diff --git a/src/commands/music_database/rescan.rs b/src/commands/music_database/rescan.rs index 624ebd5..8f18d7d 100644 --- a/src/commands/music_database/rescan.rs +++ b/src/commands/music_database/rescan.rs @@ -3,15 +3,11 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{ - Command, CommandResponse, ResponseParserError, single_optional_item_command_request, - }, + commands::{CommandResponse, ResponseParserError, single_optional_item_command_request}, response_tokenizer::{ResponseAttributes, get_and_parse_property}, types::Uri, }; -pub struct Rescan; - single_optional_item_command_request!(Rescan, "rescan", Uri); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -26,6 +22,8 @@ impl RescanResponse { } impl CommandResponse for RescanResponse { + type Request = RescanRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: HashMap<_, _> = parts.into_map()?; @@ -33,9 +31,8 @@ impl CommandResponse for RescanResponse { Ok(RescanResponse { updating_db }) } -} -impl Command for Rescan { - type Request = RescanRequest; - type Response = RescanResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for RescanResponse") + } } diff --git a/src/commands/music_database/search.rs b/src/commands/music_database/search.rs index c80242f..77dfc31 100644 --- a/src/commands/music_database/search.rs +++ b/src/commands/music_database/search.rs @@ -1,15 +1,13 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, filter::Filter, request_tokenizer::RequestTokenizer, response_tokenizer::ResponseAttributes, types::{DbSelectionPrintResponse, DbSongInfo, Sort, WindowRange}, }; -pub struct Search; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SearchRequest { filter: Filter, @@ -28,6 +26,8 @@ impl SearchRequest { } impl CommandRequest for SearchRequest { + type Response = SearchResponse; + const COMMAND: &'static str = "search"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(3); @@ -113,6 +113,8 @@ impl SearchResponse { } impl CommandResponse for SearchResponse { + type Request = SearchRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { DbSelectionPrintResponse::parse(parts)? .into_iter() @@ -128,9 +130,8 @@ impl CommandResponse for SearchResponse { .collect::, ResponseParserError>>() .map(SearchResponse) } -} -impl Command for Search { - type Request = SearchRequest; - type Response = SearchResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for SearchResponse") + } } diff --git a/src/commands/music_database/searchadd.rs b/src/commands/music_database/searchadd.rs index ea215c4..f51c6f7 100644 --- a/src/commands/music_database/searchadd.rs +++ b/src/commands/music_database/searchadd.rs @@ -1,14 +1,12 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, filter::Filter, request_tokenizer::RequestTokenizer, types::{SongPosition, Sort, WindowRange}, }; -pub struct SearchAdd; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SearchAddRequest { filter: Filter, @@ -34,6 +32,8 @@ impl SearchAddRequest { } impl CommandRequest for SearchAddRequest { + type Response = SearchAddResponse; + const COMMAND: &'static str = "searchadd"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(4); @@ -134,8 +134,3 @@ impl CommandRequest for SearchAddRequest { } empty_command_response!(SearchAdd); - -impl Command for SearchAdd { - type Request = SearchAddRequest; - type Response = SearchAddResponse; -} diff --git a/src/commands/music_database/searchaddpl.rs b/src/commands/music_database/searchaddpl.rs index aba5c7e..6713623 100644 --- a/src/commands/music_database/searchaddpl.rs +++ b/src/commands/music_database/searchaddpl.rs @@ -1,14 +1,12 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, filter::Filter, request_tokenizer::RequestTokenizer, types::{PlaylistName, SongPosition, Sort, WindowRange}, }; -pub struct SearchAddPl; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SearchAddPlRequest { playlist_name: PlaylistName, @@ -37,6 +35,8 @@ impl SearchAddPlRequest { } impl CommandRequest for SearchAddPlRequest { + type Response = SearchAddPlResponse; + const COMMAND: &'static str = "searchaddpl"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(5); @@ -143,8 +143,3 @@ impl CommandRequest for SearchAddPlRequest { } empty_command_response!(SearchAddPl); - -impl Command for SearchAddPl { - type Request = SearchAddPlRequest; - type Response = SearchAddPlResponse; -} diff --git a/src/commands/music_database/searchcount.rs b/src/commands/music_database/searchcount.rs index ae13e30..3131c16 100644 --- a/src/commands/music_database/searchcount.rs +++ b/src/commands/music_database/searchcount.rs @@ -3,15 +3,13 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, filter::Filter, request_tokenizer::RequestTokenizer, response_tokenizer::{ResponseAttributes, get_and_parse_property}, types::{GroupType, Seconds}, }; -pub struct SearchCount; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SearchCountRequest { filter: Filter, @@ -25,6 +23,8 @@ impl SearchCountRequest { } impl CommandRequest for SearchCountRequest { + type Response = SearchCountResponse; + const COMMAND: &'static str = "searchcount"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(2); @@ -85,6 +85,8 @@ impl SearchCountResponse { } impl CommandResponse for SearchCountResponse { + type Request = SearchCountRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: HashMap<_, _> = parts.into_map()?; @@ -93,9 +95,8 @@ impl CommandResponse for SearchCountResponse { Ok(SearchCountResponse { songs, playtime }) } -} -impl Command for SearchCount { - type Request = SearchCountRequest; - type Response = SearchCountResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for SearchCountResponse") + } } diff --git a/src/commands/music_database/update.rs b/src/commands/music_database/update.rs index 2365c19..4a8fc40 100644 --- a/src/commands/music_database/update.rs +++ b/src/commands/music_database/update.rs @@ -3,15 +3,11 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{ - Command, CommandResponse, ResponseParserError, single_optional_item_command_request, - }, + commands::{CommandResponse, ResponseParserError, single_optional_item_command_request}, response_tokenizer::{ResponseAttributes, get_and_parse_property}, types::Uri, }; -pub struct Update; - single_optional_item_command_request!(Update, "update", Uri); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -26,6 +22,8 @@ impl UpdateResponse { } impl CommandResponse for UpdateResponse { + type Request = UpdateRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: HashMap<_, _> = parts.into_map()?; @@ -33,9 +31,8 @@ impl CommandResponse for UpdateResponse { Ok(UpdateResponse { updating_db }) } -} -impl Command for Update { - type Request = UpdateRequest; - type Response = UpdateResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for UpdateResponse") + } } diff --git a/src/commands/partition_commands/delpartition.rs b/src/commands/partition_commands/delpartition.rs index 79fdf04..fe7d218 100644 --- a/src/commands/partition_commands/delpartition.rs +++ b/src/commands/partition_commands/delpartition.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::PartitionName, }; -pub struct DelPartition; - single_item_command_request!(DelPartition, "delpartition", PartitionName); empty_command_response!(DelPartition); - -impl Command for DelPartition { - type Request = DelPartitionRequest; - type Response = DelPartitionResponse; -} diff --git a/src/commands/partition_commands/listpartitions.rs b/src/commands/partition_commands/listpartitions.rs index 89b99f1..03dab64 100644 --- a/src/commands/partition_commands/listpartitions.rs +++ b/src/commands/partition_commands/listpartitions.rs @@ -1,16 +1,9 @@ use crate::{ - commands::{Command, ResponseParserError, empty_command_request, multi_item_command_response}, + commands::{ResponseParserError, empty_command_request, multi_item_command_response}, response_tokenizer::expect_property_type, types::PartitionName, }; -pub struct ListPartitions; - empty_command_request!(ListPartitions, "listpartitions"); multi_item_command_response!(ListPartitions, "partition", PartitionName); - -impl Command for ListPartitions { - type Request = ListPartitionsRequest; - type Response = ListPartitionsResponse; -} diff --git a/src/commands/partition_commands/moveoutput.rs b/src/commands/partition_commands/moveoutput.rs index e686f48..cee1151 100644 --- a/src/commands/partition_commands/moveoutput.rs +++ b/src/commands/partition_commands/moveoutput.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_response, single_item_command_request}; - -pub struct MoveOutput; +use crate::commands::{empty_command_response, single_item_command_request}; single_item_command_request!(MoveOutput, "moveoutput", String); empty_command_response!(MoveOutput); - -impl Command for MoveOutput { - type Request = MoveOutputRequest; - type Response = MoveOutputResponse; -} diff --git a/src/commands/partition_commands/newpartition.rs b/src/commands/partition_commands/newpartition.rs index cf4d6ff..62c937b 100644 --- a/src/commands/partition_commands/newpartition.rs +++ b/src/commands/partition_commands/newpartition.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::PartitionName, }; -pub struct NewPartition; - single_item_command_request!(NewPartition, "newpartition", PartitionName); empty_command_response!(NewPartition); - -impl Command for NewPartition { - type Request = NewPartitionRequest; - type Response = NewPartitionResponse; -} diff --git a/src/commands/partition_commands/partition.rs b/src/commands/partition_commands/partition.rs index 408b73b..e7d9cef 100644 --- a/src/commands/partition_commands/partition.rs +++ b/src/commands/partition_commands/partition.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::PartitionName, }; -pub struct Partition; - single_item_command_request!(Partition, "partition", PartitionName); empty_command_response!(Partition); - -impl Command for Partition { - type Request = PartitionRequest; - type Response = PartitionResponse; -} diff --git a/src/commands/playback_options/consume.rs b/src/commands/playback_options/consume.rs index 5c95ccd..753adec 100644 --- a/src/commands/playback_options/consume.rs +++ b/src/commands/playback_options/consume.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::BoolOrOneshot, }; -pub struct Consume; - single_item_command_request!(Consume, "consume", BoolOrOneshot); empty_command_response!(Consume); - -impl Command for Consume { - type Request = ConsumeRequest; - type Response = ConsumeResponse; -} diff --git a/src/commands/playback_options/crossfade.rs b/src/commands/playback_options/crossfade.rs index 15f6754..a520cf9 100644 --- a/src/commands/playback_options/crossfade.rs +++ b/src/commands/playback_options/crossfade.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::Seconds, }; -pub struct Crossfade; - single_item_command_request!(Crossfade, "crossfade", Seconds); empty_command_response!(Crossfade); - -impl Command for Crossfade { - type Request = CrossfadeRequest; - type Response = CrossfadeResponse; -} diff --git a/src/commands/playback_options/getvol.rs b/src/commands/playback_options/getvol.rs index 134fa64..6542d43 100644 --- a/src/commands/playback_options/getvol.rs +++ b/src/commands/playback_options/getvol.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_request, single_item_command_response}, + commands::{empty_command_request, single_item_command_response}, types::VolumeValue, }; -pub struct GetVol; - empty_command_request!(GetVol, "getvol"); single_item_command_response!(GetVol, "volume", VolumeValue); - -impl Command for GetVol { - type Request = GetVolRequest; - type Response = GetVolResponse; -} diff --git a/src/commands/playback_options/mixrampdb.rs b/src/commands/playback_options/mixrampdb.rs index 0a06c40..666d079 100644 --- a/src/commands/playback_options/mixrampdb.rs +++ b/src/commands/playback_options/mixrampdb.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_response, single_item_command_request}; - -pub struct MixRampDb; +use crate::commands::{empty_command_response, single_item_command_request}; single_item_command_request!(MixRampDb, "mixrampdb", f32); empty_command_response!(MixRampDb); - -impl Command for MixRampDb { - type Request = MixRampDbRequest; - type Response = MixRampDbResponse; -} diff --git a/src/commands/playback_options/mixrampdelay.rs b/src/commands/playback_options/mixrampdelay.rs index f165272..f02b0d8 100644 --- a/src/commands/playback_options/mixrampdelay.rs +++ b/src/commands/playback_options/mixrampdelay.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::Seconds, }; -pub struct MixRampDelay; - single_item_command_request!(MixRampDelay, "mixrampdelay", Seconds); empty_command_response!(MixRampDelay); - -impl Command for MixRampDelay { - type Request = MixRampDelayRequest; - type Response = MixRampDelayResponse; -} diff --git a/src/commands/playback_options/random.rs b/src/commands/playback_options/random.rs index b031bfe..5626b11 100644 --- a/src/commands/playback_options/random.rs +++ b/src/commands/playback_options/random.rs @@ -1,10 +1,8 @@ use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, }; -pub struct Random; - pub struct RandomRequest(bool); impl RandomRequest { @@ -14,6 +12,8 @@ impl RandomRequest { } impl CommandRequest for RandomRequest { + type Response = RandomResponse; + const COMMAND: &'static str = "random"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(1); @@ -44,8 +44,3 @@ impl CommandRequest for RandomRequest { } empty_command_response!(Random); - -impl Command for Random { - type Request = RandomRequest; - type Response = RandomResponse; -} diff --git a/src/commands/playback_options/repeat.rs b/src/commands/playback_options/repeat.rs index 461216f..2828069 100644 --- a/src/commands/playback_options/repeat.rs +++ b/src/commands/playback_options/repeat.rs @@ -1,10 +1,8 @@ use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, }; -pub struct Repeat; - pub struct RepeatRequest(bool); impl RepeatRequest { @@ -14,6 +12,8 @@ impl RepeatRequest { } impl CommandRequest for RepeatRequest { + type Response = RepeatResponse; + const COMMAND: &'static str = "repeat"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(1); @@ -44,8 +44,3 @@ impl CommandRequest for RepeatRequest { } empty_command_response!(Repeat); - -impl Command for Repeat { - type Request = RepeatRequest; - type Response = RepeatResponse; -} diff --git a/src/commands/playback_options/replay_gain_mode.rs b/src/commands/playback_options/replay_gain_mode.rs index fdf0fc6..25184dc 100644 --- a/src/commands/playback_options/replay_gain_mode.rs +++ b/src/commands/playback_options/replay_gain_mode.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::ReplayGainModeMode, }; -pub struct ReplayGainMode; - single_item_command_request!(ReplayGainMode, "replay_gain_mode", ReplayGainModeMode); empty_command_response!(ReplayGainMode); - -impl Command for ReplayGainMode { - type Request = ReplayGainModeRequest; - type Response = ReplayGainModeResponse; -} diff --git a/src/commands/playback_options/replay_gain_status.rs b/src/commands/playback_options/replay_gain_status.rs index d897923..317d800 100644 --- a/src/commands/playback_options/replay_gain_status.rs +++ b/src/commands/playback_options/replay_gain_status.rs @@ -3,13 +3,11 @@ use std::{collections::HashMap, str::FromStr}; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, empty_command_request}, + commands::{CommandResponse, ResponseParserError, empty_command_request}, response_tokenizer::{ResponseAttributes, get_property}, types::ReplayGainModeMode, }; -pub struct ReplayGainStatus; - empty_command_request!(ReplayGainStatus, "replay_gain_status"); #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -24,6 +22,8 @@ impl ReplayGainStatusResponse { } impl CommandResponse for ReplayGainStatusResponse { + type Request = ReplayGainStatusRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: HashMap<_, _> = parts.into_map()?; let replay_gain_mode = get_property!(parts, "replay_gain_mode", Text); @@ -37,9 +37,8 @@ impl CommandResponse for ReplayGainStatusResponse { })?, }) } -} -impl Command for ReplayGainStatus { - type Request = ReplayGainStatusRequest; - type Response = ReplayGainStatusResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for ReplayGainStatusResponse") + } } diff --git a/src/commands/playback_options/setvol.rs b/src/commands/playback_options/setvol.rs index 59daaa4..71d203c 100644 --- a/src/commands/playback_options/setvol.rs +++ b/src/commands/playback_options/setvol.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::VolumeValue, }; -pub struct SetVol; - single_item_command_request!(SetVol, "setvol", VolumeValue); empty_command_response!(SetVol); - -impl Command for SetVol { - type Request = SetVolRequest; - type Response = SetVolResponse; -} diff --git a/src/commands/playback_options/single.rs b/src/commands/playback_options/single.rs index d1b4428..3a3d781 100644 --- a/src/commands/playback_options/single.rs +++ b/src/commands/playback_options/single.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::BoolOrOneshot, }; -pub struct Single; - single_item_command_request!(Single, "single", BoolOrOneshot); empty_command_response!(Single); - -impl Command for Single { - type Request = SingleRequest; - type Response = SingleResponse; -} diff --git a/src/commands/playback_options/volume.rs b/src/commands/playback_options/volume.rs index 51a1c4c..16d7e80 100644 --- a/src/commands/playback_options/volume.rs +++ b/src/commands/playback_options/volume.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::VolumeValue, }; -pub struct Volume; - single_item_command_request!(Volume, "volume", VolumeValue); empty_command_response!(Volume); - -impl Command for Volume { - type Request = VolumeRequest; - type Response = VolumeResponse; -} diff --git a/src/commands/querying_mpd_status/clearerror.rs b/src/commands/querying_mpd_status/clearerror.rs index 21b8c3d..156f8b7 100644 --- a/src/commands/querying_mpd_status/clearerror.rs +++ b/src/commands/querying_mpd_status/clearerror.rs @@ -1,13 +1,6 @@ -use crate::commands::{Command, empty_command_request, empty_command_response}; - -/// Clears the current error message in status (this is also accomplished by any command that starts playback) -pub struct ClearError; +use crate::commands::{empty_command_request, empty_command_response}; +// Clears the current error message in status (this is also accomplished by any command that starts playback) empty_command_request!(ClearError, "clearerror"); empty_command_response!(ClearError); - -impl Command for ClearError { - type Request = ClearErrorRequest; - type Response = ClearErrorResponse; -} diff --git a/src/commands/querying_mpd_status/currentsong.rs b/src/commands/querying_mpd_status/currentsong.rs index 28d650c..efd499d 100644 --- a/src/commands/querying_mpd_status/currentsong.rs +++ b/src/commands/querying_mpd_status/currentsong.rs @@ -3,16 +3,14 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, empty_command_request}, + commands::{CommandResponse, ResponseParserError, empty_command_request}, response_tokenizer::{ ResponseAttributes, get_and_parse_optional_property, get_and_parse_property, }, types::{DbSongInfo, Priority, SongId, SongPosition}, }; -/// Displays the song info of the current song (same song that is identified in status) -pub struct CurrentSong; - +// Displays the song info of the current song (same song that is identified in status) empty_command_request!(CurrentSong, "currentsong"); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -40,6 +38,8 @@ impl CurrentSongResponse { } impl CommandResponse for CurrentSongResponse { + type Request = CurrentSongRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let mut parts: HashMap<_, _> = parts.into_map()?; @@ -60,9 +60,8 @@ impl CommandResponse for CurrentSongResponse { song_info, }) } -} -impl Command for CurrentSong { - type Request = CurrentSongRequest; - type Response = CurrentSongResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for CurrentSongResponse") + } } diff --git a/src/commands/querying_mpd_status/idle.rs b/src/commands/querying_mpd_status/idle.rs index a383a0f..d217a74 100644 --- a/src/commands/querying_mpd_status/idle.rs +++ b/src/commands/querying_mpd_status/idle.rs @@ -1,13 +1,11 @@ use std::str::FromStr; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::SubSystem, }; -pub struct Idle; - pub struct IdleRequest(Option>); impl IdleRequest { @@ -17,6 +15,8 @@ impl IdleRequest { } impl CommandRequest for IdleRequest { + type Response = IdleResponse; + const COMMAND: &'static str = "idle"; const MIN_ARGS: u32 = 0; const MAX_ARGS: Option = None; @@ -50,8 +50,3 @@ impl CommandRequest for IdleRequest { } empty_command_response!(Idle); - -impl Command for Idle { - type Request = IdleRequest; - type Response = IdleResponse; -} diff --git a/src/commands/querying_mpd_status/stats.rs b/src/commands/querying_mpd_status/stats.rs index 86f8a60..3cc3bc6 100644 --- a/src/commands/querying_mpd_status/stats.rs +++ b/src/commands/querying_mpd_status/stats.rs @@ -3,14 +3,12 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, empty_command_request}, + commands::{CommandResponse, ResponseParserError, empty_command_request}, response_tokenizer::{ ResponseAttributes, get_and_parse_optional_property, get_and_parse_property, }, }; -pub struct Stats; - empty_command_request!(Stats, "stats"); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -47,6 +45,8 @@ impl StatsResponse { } impl CommandResponse for StatsResponse { + type Request = StatsRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: HashMap<_, _> = parts.into_map()?; @@ -68,9 +68,8 @@ impl CommandResponse for StatsResponse { db_update, }) } -} -impl Command for Stats { - type Request = StatsRequest; - type Response = StatsResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for StatsResponse") + } } diff --git a/src/commands/querying_mpd_status/status.rs b/src/commands/querying_mpd_status/status.rs index ea01c03..bd16e89 100644 --- a/src/commands/querying_mpd_status/status.rs +++ b/src/commands/querying_mpd_status/status.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, empty_command_request}, + commands::{CommandResponse, ResponseParserError, empty_command_request}, response_tokenizer::{ ResponseAttributes, get_and_parse_optional_property, get_and_parse_property, get_optional_property, get_property, @@ -12,8 +12,6 @@ use crate::{ types::{Audio, BoolOrOneshot, SongId, SongPosition}, }; -pub struct Status; - empty_command_request!(Status, "status"); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -122,6 +120,8 @@ impl StatusResponse { } impl CommandResponse for StatusResponse { + type Request = StatusRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: HashMap<_, _> = parts.into_map()?; let partition = get_property!(parts, "partition", Text).to_string(); @@ -224,11 +224,10 @@ impl CommandResponse for StatusResponse { last_loaded_playlist, }) } -} -impl Command for Status { - type Request = StatusRequest; - type Response = StatusResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for StatusResponse") + } } #[cfg(test)] @@ -263,7 +262,7 @@ mod tests { "# }; assert_eq!( - Status::parse_raw_response(contents.as_bytes()), + StatusResponse::parse_raw(contents.as_bytes()), Ok(StatusResponse { partition: "default".into(), volume: Some(66), diff --git a/src/commands/queue/add.rs b/src/commands/queue/add.rs index 7eab4eb..a9a26a8 100644 --- a/src/commands/queue/add.rs +++ b/src/commands/queue/add.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{SongPosition, Uri}, }; -pub struct Add; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct AddRequest { uri: Uri, @@ -21,6 +19,8 @@ impl AddRequest { } impl CommandRequest for AddRequest { + type Response = AddResponse; + const COMMAND: &'static str = "add"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(2); @@ -59,8 +59,3 @@ impl CommandRequest for AddRequest { } empty_command_response!(Add); - -impl Command for Add { - type Request = AddRequest; - type Response = AddResponse; -} diff --git a/src/commands/queue/addid.rs b/src/commands/queue/addid.rs index 88538b1..569fe03 100644 --- a/src/commands/queue/addid.rs +++ b/src/commands/queue/addid.rs @@ -1,14 +1,12 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, request_tokenizer::RequestTokenizer, response_tokenizer::{ResponseAttributes, get_next_and_parse_property}, types::{SongId, SongPosition, Uri}, }; -pub struct AddId; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct AddIdRequest { pub uri: Uri, @@ -22,6 +20,8 @@ impl AddIdRequest { } impl CommandRequest for AddIdRequest { + type Response = AddIdResponse; + const COMMAND: &'static str = "addid"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(2); @@ -71,6 +71,8 @@ impl AddIdResponse { } impl CommandResponse for AddIdResponse { + type Request = AddIdRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: Vec<_> = parts.into(); let mut iter = parts.into_iter(); @@ -80,9 +82,8 @@ impl CommandResponse for AddIdResponse { } Ok(AddIdResponse { id }) } -} -impl Command for AddId { - type Request = AddIdRequest; - type Response = AddIdResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for AddIdResponse") + } } diff --git a/src/commands/queue/addtagid.rs b/src/commands/queue/addtagid.rs index f7f0eee..de8fe52 100644 --- a/src/commands/queue/addtagid.rs +++ b/src/commands/queue/addtagid.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{SongId, TagName, TagValue}, }; -pub struct AddTagId; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct AddTagIdRequest { pub songid: SongId, @@ -26,6 +24,8 @@ impl AddTagIdRequest { } impl CommandRequest for AddTagIdRequest { + type Response = AddTagIdResponse; + const COMMAND: &'static str = "addtagid"; const MIN_ARGS: u32 = 3; const MAX_ARGS: Option = Some(3); @@ -79,8 +79,3 @@ impl CommandRequest for AddTagIdRequest { } empty_command_response!(AddTagId); - -impl Command for AddTagId { - type Request = AddTagIdRequest; - type Response = AddTagIdResponse; -} diff --git a/src/commands/queue/clear.rs b/src/commands/queue/clear.rs index aad90b5..5ceb7a9 100644 --- a/src/commands/queue/clear.rs +++ b/src/commands/queue/clear.rs @@ -1,12 +1,5 @@ -use crate::commands::{Command, empty_command_request, empty_command_response}; - -pub struct Clear; +use crate::commands::{empty_command_request, empty_command_response}; empty_command_request!(Clear, "clear"); empty_command_response!(Clear); - -impl Command for Clear { - type Request = ClearRequest; - type Response = ClearResponse; -} diff --git a/src/commands/queue/cleartagid.rs b/src/commands/queue/cleartagid.rs index 84e071c..47b604a 100644 --- a/src/commands/queue/cleartagid.rs +++ b/src/commands/queue/cleartagid.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{SongId, TagName}, }; -pub struct ClearTagId; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ClearTagIdRequest { pub songid: SongId, @@ -21,6 +19,8 @@ impl ClearTagIdRequest { } impl CommandRequest for ClearTagIdRequest { + type Response = ClearTagIdResponse; + const COMMAND: &'static str = "cleartagid"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -55,8 +55,3 @@ impl CommandRequest for ClearTagIdRequest { } empty_command_response!(ClearTagId); - -impl Command for ClearTagId { - type Request = ClearTagIdRequest; - type Response = ClearTagIdResponse; -} diff --git a/src/commands/queue/delete.rs b/src/commands/queue/delete.rs index b304573..e4e0b1f 100644 --- a/src/commands/queue/delete.rs +++ b/src/commands/queue/delete.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::OneOrRange, }; -pub struct Delete; - single_item_command_request!(Delete, "delete", OneOrRange); empty_command_response!(Delete); - -impl Command for Delete { - type Request = DeleteRequest; - type Response = DeleteResponse; -} diff --git a/src/commands/queue/deleteid.rs b/src/commands/queue/deleteid.rs index e13be58..97f8dba 100644 --- a/src/commands/queue/deleteid.rs +++ b/src/commands/queue/deleteid.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::SongId, }; -pub struct DeleteId; - single_item_command_request!(DeleteId, "deleteid", SongId); empty_command_response!(DeleteId); - -impl Command for DeleteId { - type Request = DeleteIdRequest; - type Response = DeleteIdResponse; -} diff --git a/src/commands/queue/move_.rs b/src/commands/queue/move_.rs index 86f08de..b5005f3 100644 --- a/src/commands/queue/move_.rs +++ b/src/commands/queue/move_.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{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, @@ -21,6 +19,8 @@ impl MoveRequest { } impl CommandRequest for MoveRequest { + type Response = MoveResponse; + const COMMAND: &'static str = "move"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -56,8 +56,3 @@ impl CommandRequest for MoveRequest { } empty_command_response!(Move); - -impl Command for Move { - type Request = MoveRequest; - type Response = MoveResponse; -} diff --git a/src/commands/queue/moveid.rs b/src/commands/queue/moveid.rs index 33c8b81..04cb006 100644 --- a/src/commands/queue/moveid.rs +++ b/src/commands/queue/moveid.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{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, @@ -21,6 +19,8 @@ impl MoveIdRequest { } impl CommandRequest for MoveIdRequest { + type Response = MoveIdResponse; + const COMMAND: &'static str = "moveid"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -55,8 +55,3 @@ impl CommandRequest for MoveIdRequest { } empty_command_response!(MoveId); - -impl Command for MoveId { - type Request = MoveIdRequest; - type Response = MoveIdResponse; -} diff --git a/src/commands/queue/playlist.rs b/src/commands/queue/playlist.rs index 9606519..c42ed51 100644 --- a/src/commands/queue/playlist.rs +++ b/src/commands/queue/playlist.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, empty_command_request}, + commands::{CommandResponse, ResponseParserError, empty_command_request}, response_tokenizer::ResponseAttributes, types::Uri, }; -pub struct Playlist; - empty_command_request!(Playlist, "playlist"); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -20,12 +18,13 @@ impl PlaylistResponse { } impl CommandResponse for PlaylistResponse { + type Request = PlaylistRequest; + fn parse(_parts: ResponseAttributes<'_>) -> Result { unimplemented!() } -} -impl Command for Playlist { - type Request = PlaylistRequest; - type Response = PlaylistResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for PlaylistResponse") + } } diff --git a/src/commands/queue/playlistfind.rs b/src/commands/queue/playlistfind.rs index f745b94..e18c6d7 100644 --- a/src/commands/queue/playlistfind.rs +++ b/src/commands/queue/playlistfind.rs @@ -1,15 +1,13 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, filter::Filter, request_tokenizer::RequestTokenizer, response_tokenizer::ResponseAttributes, types::{DbSongInfo, Priority, SongId, SongPosition, Sort, WindowRange}, }; -pub struct PlaylistFind; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PlaylistFindRequest { filter: Filter, @@ -28,6 +26,8 @@ impl PlaylistFindRequest { } impl CommandRequest for PlaylistFindRequest { + type Response = PlaylistFindResponse; + const COMMAND: &'static str = "playlistfind"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(3); @@ -137,12 +137,13 @@ impl PlaylistFindResponseEntry { } impl CommandResponse for PlaylistFindResponse { + type Request = PlaylistFindRequest; + fn parse(_parts: ResponseAttributes<'_>) -> Result { unimplemented!() } -} -impl Command for PlaylistFind { - type Request = PlaylistFindRequest; - type Response = PlaylistFindResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for PlaylistFindResponse") + } } diff --git a/src/commands/queue/playlistid.rs b/src/commands/queue/playlistid.rs index 9fffccf..b5b684a 100644 --- a/src/commands/queue/playlistid.rs +++ b/src/commands/queue/playlistid.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, single_item_command_request}, + commands::{CommandResponse, ResponseParserError, single_item_command_request}, response_tokenizer::ResponseAttributes, types::{DbSongInfo, Priority, SongId, SongPosition}, }; -pub struct PlaylistId; - single_item_command_request!(PlaylistId, "playlistid", SongId); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -44,12 +42,13 @@ impl PlaylistIdResponseEntry { } impl CommandResponse for PlaylistIdResponse { + type Request = PlaylistIdRequest; + fn parse(_parts: ResponseAttributes<'_>) -> Result { unimplemented!() } -} -impl Command for PlaylistId { - type Request = PlaylistIdRequest; - type Response = PlaylistIdResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for PlaylistIdResponse") + } } diff --git a/src/commands/queue/playlistinfo.rs b/src/commands/queue/playlistinfo.rs index 2b8d040..db772bd 100644 --- a/src/commands/queue/playlistinfo.rs +++ b/src/commands/queue/playlistinfo.rs @@ -1,15 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{ - Command, CommandResponse, ResponseParserError, single_optional_item_command_request, - }, + commands::{CommandResponse, ResponseParserError, single_optional_item_command_request}, response_tokenizer::ResponseAttributes, types::{DbSongInfo, OneOrRange, Priority, SongId, SongPosition}, }; -pub struct PlaylistInfo; - single_optional_item_command_request!(PlaylistInfo, "playlistinfo", OneOrRange); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -46,12 +42,13 @@ impl PlaylistInfoResponseEntry { } impl CommandResponse for PlaylistInfoResponse { + type Request = PlaylistInfoRequest; + fn parse(_parts: ResponseAttributes<'_>) -> Result { unimplemented!() } -} -impl Command for PlaylistInfo { - type Request = PlaylistInfoRequest; - type Response = PlaylistInfoResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for PlaylistInfoResponse") + } } diff --git a/src/commands/queue/playlistsearch.rs b/src/commands/queue/playlistsearch.rs index 671b79f..83ac2d4 100644 --- a/src/commands/queue/playlistsearch.rs +++ b/src/commands/queue/playlistsearch.rs @@ -1,15 +1,13 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, filter::Filter, request_tokenizer::RequestTokenizer, response_tokenizer::ResponseAttributes, types::{DbSongInfo, Priority, SongId, SongPosition, Sort, WindowRange}, }; -pub struct PlaylistSearch; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PlaylistSearchRequest { filter: Filter, @@ -28,6 +26,8 @@ impl PlaylistSearchRequest { } impl CommandRequest for PlaylistSearchRequest { + type Response = PlaylistSearchResponse; + const COMMAND: &'static str = "playlistsearch"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(3); @@ -137,12 +137,13 @@ impl PlaylistSearchResponseEntry { } impl CommandResponse for PlaylistSearchResponse { + type Request = PlaylistSearchRequest; + fn parse(_parts: ResponseAttributes<'_>) -> Result { unimplemented!() } -} -impl Command for PlaylistSearch { - type Request = PlaylistSearchRequest; - type Response = PlaylistSearchResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for PlaylistSearchResponse") + } } diff --git a/src/commands/queue/plchanges.rs b/src/commands/queue/plchanges.rs index 85f183f..5de9aa5 100644 --- a/src/commands/queue/plchanges.rs +++ b/src/commands/queue/plchanges.rs @@ -1,14 +1,12 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, request_tokenizer::RequestTokenizer, response_tokenizer::ResponseAttributes, types::{DbSongInfo, PlaylistVersion, Priority, SongId, SongPosition, WindowRange}, }; -pub struct PlChanges; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PlChangesRequest { pub version: PlaylistVersion, @@ -22,6 +20,8 @@ impl PlChangesRequest { } impl CommandRequest for PlChangesRequest { + type Response = PlChangesResponse; + const COMMAND: &'static str = "plchanges"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(2); @@ -95,12 +95,13 @@ impl PlChangesResponseEntry { } impl CommandResponse for PlChangesResponse { + type Request = PlChangesRequest; + fn parse(_parts: ResponseAttributes<'_>) -> Result { unimplemented!() } -} -impl Command for PlChanges { - type Request = PlChangesRequest; - type Response = PlChangesResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for PlChangesResponse") + } } diff --git a/src/commands/queue/plchangesposid.rs b/src/commands/queue/plchangesposid.rs index 18ac166..72342b2 100644 --- a/src/commands/queue/plchangesposid.rs +++ b/src/commands/queue/plchangesposid.rs @@ -1,14 +1,12 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{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, @@ -22,6 +20,8 @@ impl PlChangesPosIdRequest { } impl CommandRequest for PlChangesPosIdRequest { + type Response = PlChangesPosIdResponse; + const COMMAND: &'static str = "plchangesposid"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(2); @@ -84,12 +84,13 @@ impl PlChangesPosIdResponseEntry { } impl CommandResponse for PlChangesPosIdResponse { + type Request = PlChangesPosIdRequest; + fn parse(_parts: ResponseAttributes<'_>) -> Result { unimplemented!() } -} -impl Command for PlChangesPosId { - type Request = PlChangesPosIdRequest; - type Response = PlChangesPosIdResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for PlChangesPosIdResponse") + } } diff --git a/src/commands/queue/prio.rs b/src/commands/queue/prio.rs index ca773b5..3468d19 100644 --- a/src/commands/queue/prio.rs +++ b/src/commands/queue/prio.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{Priority, WindowRange}, }; -pub struct Prio; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PrioRequest { pub prio: Priority, @@ -21,6 +19,8 @@ impl PrioRequest { } impl CommandRequest for PrioRequest { + type Response = PrioResponse; + const COMMAND: &'static str = "prio"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -55,8 +55,3 @@ impl CommandRequest for PrioRequest { } empty_command_response!(Prio); - -impl Command for Prio { - type Request = PrioRequest; - type Response = PrioResponse; -} diff --git a/src/commands/queue/prioid.rs b/src/commands/queue/prioid.rs index 753943d..c3767b2 100644 --- a/src/commands/queue/prioid.rs +++ b/src/commands/queue/prioid.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{Priority, SongId}, }; -pub struct PrioId; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PrioIdRequest { pub prio: Priority, @@ -21,6 +19,8 @@ impl PrioIdRequest { } impl CommandRequest for PrioIdRequest { + type Response = PrioIdResponse; + const COMMAND: &'static str = "prioid"; const MIN_ARGS: u32 = 2; // TODO: should this be 2? @@ -63,8 +63,3 @@ impl CommandRequest for PrioIdRequest { } empty_command_response!(PrioId); - -impl Command for PrioId { - type Request = PrioIdRequest; - type Response = PrioIdResponse; -} diff --git a/src/commands/queue/rangeid.rs b/src/commands/queue/rangeid.rs index d01d7d7..f7ae3ea 100644 --- a/src/commands/queue/rangeid.rs +++ b/src/commands/queue/rangeid.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{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, @@ -24,6 +22,8 @@ impl RangeIdRequest { } impl CommandRequest for RangeIdRequest { + type Response = RangeIdResponse; + const COMMAND: &'static str = "rangeid"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -62,8 +62,3 @@ impl CommandRequest for RangeIdRequest { } empty_command_response!(RangeId); - -impl Command for RangeId { - type Request = RangeIdRequest; - type Response = RangeIdResponse; -} diff --git a/src/commands/queue/shuffle.rs b/src/commands/queue/shuffle.rs index 80e0e2e..fa8dbf7 100644 --- a/src/commands/queue/shuffle.rs +++ b/src/commands/queue/shuffle.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_optional_item_command_request}, + commands::{empty_command_response, single_optional_item_command_request}, types::OneOrRange, }; -pub struct Shuffle; - single_optional_item_command_request!(Shuffle, "shuffle", OneOrRange); empty_command_response!(Shuffle); - -impl Command for Shuffle { - type Request = ShuffleRequest; - type Response = ShuffleResponse; -} diff --git a/src/commands/queue/swap.rs b/src/commands/queue/swap.rs index a7bad37..b24e670 100644 --- a/src/commands/queue/swap.rs +++ b/src/commands/queue/swap.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::SongPosition, }; -pub struct Swap; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SwapRequest { pub songpos1: SongPosition, @@ -21,6 +19,8 @@ impl SwapRequest { } impl CommandRequest for SwapRequest { + type Response = SwapResponse; + const COMMAND: &'static str = "swap"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -55,8 +55,3 @@ impl CommandRequest for SwapRequest { } empty_command_response!(Swap); - -impl Command for Swap { - type Request = SwapRequest; - type Response = SwapResponse; -} diff --git a/src/commands/queue/swapid.rs b/src/commands/queue/swapid.rs index 2875d06..3eb988f 100644 --- a/src/commands/queue/swapid.rs +++ b/src/commands/queue/swapid.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::SongId, }; -pub struct SwapId; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SwapIdRequest { pub songid1: SongId, @@ -21,6 +19,8 @@ impl SwapIdRequest { } impl CommandRequest for SwapIdRequest { + type Response = SwapIdResponse; + const COMMAND: &'static str = "swapid"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -55,8 +55,3 @@ impl CommandRequest for SwapIdRequest { } empty_command_response!(SwapId); - -impl Command for SwapId { - type Request = SwapIdRequest; - type Response = SwapIdResponse; -} diff --git a/src/commands/reflection/commands.rs b/src/commands/reflection/commands.rs index ba6360d..1c36a1d 100644 --- a/src/commands/reflection/commands.rs +++ b/src/commands/reflection/commands.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, ResponseParserError, empty_command_request, multi_item_command_response}, + commands::{ResponseParserError, empty_command_request, multi_item_command_response}, response_tokenizer::expect_property_type, }; -pub struct Commands; - empty_command_request!(Commands, "commands"); multi_item_command_response!(Commands, "command", String); - -impl Command for Commands { - type Request = CommandsRequest; - type Response = CommandsResponse; -} diff --git a/src/commands/reflection/config.rs b/src/commands/reflection/config.rs index 54f3edd..d3b43ef 100644 --- a/src/commands/reflection/config.rs +++ b/src/commands/reflection/config.rs @@ -3,12 +3,10 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, empty_command_request}, + commands::{CommandResponse, ResponseParserError, empty_command_request}, response_tokenizer::{ResponseAttributes, get_and_parse_property, get_property}, }; -pub struct Config; - empty_command_request!(Config, "config"); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -29,6 +27,8 @@ impl ConfigResponse { } impl CommandResponse for ConfigResponse { + type Request = ConfigRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: HashMap<_, _> = parts.into_map()?; @@ -44,9 +44,8 @@ impl CommandResponse for ConfigResponse { pcre, }) } -} -impl Command for Config { - type Request = ConfigRequest; - type Response = ConfigResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for ConfigResponse") + } } diff --git a/src/commands/reflection/decoders.rs b/src/commands/reflection/decoders.rs index a001743..7a430b6 100644 --- a/src/commands/reflection/decoders.rs +++ b/src/commands/reflection/decoders.rs @@ -1,12 +1,10 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, empty_command_request}, + commands::{CommandResponse, ResponseParserError, empty_command_request}, response_tokenizer::{ResponseAttributes, expect_property_type}, }; -pub struct Decoders; - empty_command_request!(Decoders, "decoders"); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -36,6 +34,8 @@ impl DecodersResponse { } impl CommandResponse for DecodersResponse { + type Request = DecodersRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let mut result = Vec::new(); let mut current_decoder: Option = None; @@ -80,11 +80,10 @@ impl CommandResponse for DecodersResponse { Ok(DecodersResponse(result)) } -} -impl Command for Decoders { - type Request = DecodersRequest; - type Response = DecodersResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for DecodersResponse") + } } #[cfg(test)] @@ -114,7 +113,7 @@ mod tests { mime_type: audio/x-mpd-alsa-pcm OK "}; - let result = Decoders::parse_raw_response(input.as_bytes()); + let result = DecodersResponse::parse_raw(input.as_bytes()); assert_eq!( result, Ok(DecodersResponse(vec![ diff --git a/src/commands/reflection/not_commands.rs b/src/commands/reflection/not_commands.rs index 84fead6..a3f28c9 100644 --- a/src/commands/reflection/not_commands.rs +++ b/src/commands/reflection/not_commands.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, ResponseParserError, empty_command_request, multi_item_command_response}, + commands::{ResponseParserError, empty_command_request, multi_item_command_response}, response_tokenizer::expect_property_type, }; -pub struct NotCommands; - empty_command_request!(NotCommands, "notcommands"); multi_item_command_response!(NotCommands, "command", String); - -impl Command for NotCommands { - type Request = NotCommandsRequest; - type Response = NotCommandsResponse; -} diff --git a/src/commands/reflection/url_handlers.rs b/src/commands/reflection/url_handlers.rs index edf9507..ce6f4e2 100644 --- a/src/commands/reflection/url_handlers.rs +++ b/src/commands/reflection/url_handlers.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, ResponseParserError, empty_command_request, multi_item_command_response}, + commands::{ResponseParserError, empty_command_request, multi_item_command_response}, response_tokenizer::expect_property_type, }; -pub struct UrlHandlers; - empty_command_request!(UrlHandlers, "urlhandlers"); multi_item_command_response!(UrlHandlers, "handler", String); - -impl Command for UrlHandlers { - type Request = UrlHandlersRequest; - type Response = UrlHandlersResponse; -} diff --git a/src/commands/stickers/sticker_dec.rs b/src/commands/stickers/sticker_dec.rs index 652aff3..00ac070 100644 --- a/src/commands/stickers/sticker_dec.rs +++ b/src/commands/stickers/sticker_dec.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{StickerType, Uri}, }; -pub struct StickerDec; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct StickerDecRequest { pub sticker_type: StickerType, @@ -28,6 +26,8 @@ impl StickerDecRequest { } impl CommandRequest for StickerDecRequest { + type Response = StickerDecResponse; + const COMMAND: &'static str = "sticker dec"; const MIN_ARGS: u32 = 4; const MAX_ARGS: Option = Some(4); @@ -93,8 +93,3 @@ impl CommandRequest for StickerDecRequest { } empty_command_response!(StickerDec); - -impl Command for StickerDec { - type Request = StickerDecRequest; - type Response = StickerDecResponse; -} diff --git a/src/commands/stickers/sticker_delete.rs b/src/commands/stickers/sticker_delete.rs index d9a75d5..78dfdb4 100644 --- a/src/commands/stickers/sticker_delete.rs +++ b/src/commands/stickers/sticker_delete.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{StickerType, Uri}, }; -pub struct StickerDelete; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct StickerDeleteRequest { pub sticker_type: StickerType, @@ -26,6 +24,8 @@ impl StickerDeleteRequest { } impl CommandRequest for StickerDeleteRequest { + type Response = StickerDeleteResponse; + const COMMAND: &'static str = "sticker delete"; const MIN_ARGS: u32 = 3; const MAX_ARGS: Option = Some(3); @@ -80,8 +80,3 @@ impl CommandRequest for StickerDeleteRequest { } empty_command_response!(StickerDelete); - -impl Command for StickerDelete { - type Request = StickerDeleteRequest; - type Response = StickerDeleteResponse; -} diff --git a/src/commands/stickers/sticker_find.rs b/src/commands/stickers/sticker_find.rs index 2f83362..da33ea9 100644 --- a/src/commands/stickers/sticker_find.rs +++ b/src/commands/stickers/sticker_find.rs @@ -1,14 +1,12 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, request_tokenizer::RequestTokenizer, response_tokenizer::{ResponseAttributes, expect_property_type}, types::{Sort, StickerType, Uri, WindowRange}, }; -pub struct StickerFind; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct StickerFindRequest { pub sticker_type: StickerType, @@ -37,6 +35,8 @@ impl StickerFindRequest { } impl CommandRequest for StickerFindRequest { + type Response = StickerFindResponse; + const COMMAND: &'static str = "sticker find"; const MIN_ARGS: u32 = 3; const MAX_ARGS: Option = Some(5); @@ -164,6 +164,8 @@ impl StickerFindResponseEntry { } impl CommandResponse for StickerFindResponse { + type Request = StickerFindRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: Vec<_> = parts.into_vec()?; let mut stickers = Vec::with_capacity(parts.len() / 2); @@ -205,9 +207,8 @@ impl CommandResponse for StickerFindResponse { Ok(StickerFindResponse(stickers)) } -} -impl Command for StickerFind { - type Request = StickerFindRequest; - type Response = StickerFindResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for StickerFindResponse") + } } diff --git a/src/commands/stickers/sticker_get.rs b/src/commands/stickers/sticker_get.rs index 9f787e9..e082780 100644 --- a/src/commands/stickers/sticker_get.rs +++ b/src/commands/stickers/sticker_get.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, single_item_command_response}, + commands::{CommandRequest, RequestParserError, single_item_command_response}, request_tokenizer::RequestTokenizer, types::{StickerType, Uri}, }; -pub struct StickerGet; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct StickerGetRequest { pub sticker_type: StickerType, @@ -26,6 +24,8 @@ impl StickerGetRequest { } impl CommandRequest for StickerGetRequest { + type Response = StickerGetResponse; + const COMMAND: &'static str = "sticker get"; const MIN_ARGS: u32 = 3; const MAX_ARGS: Option = Some(3); @@ -80,8 +80,3 @@ impl CommandRequest for StickerGetRequest { } single_item_command_response!(StickerGet, "string", String); - -impl Command for StickerGet { - type Request = StickerGetRequest; - type Response = StickerGetResponse; -} diff --git a/src/commands/stickers/sticker_inc.rs b/src/commands/stickers/sticker_inc.rs index 67ddc4e..c943c7b 100644 --- a/src/commands/stickers/sticker_inc.rs +++ b/src/commands/stickers/sticker_inc.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{StickerType, Uri}, }; -pub struct StickerInc; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct StickerIncRequest { pub sticker_type: StickerType, @@ -28,6 +26,8 @@ impl StickerIncRequest { } impl CommandRequest for StickerIncRequest { + type Response = StickerIncResponse; + const COMMAND: &'static str = "sticker inc"; const MIN_ARGS: u32 = 4; const MAX_ARGS: Option = Some(4); @@ -93,8 +93,3 @@ impl CommandRequest for StickerIncRequest { } empty_command_response!(StickerInc); - -impl Command for StickerInc { - type Request = StickerIncRequest; - type Response = StickerIncResponse; -} diff --git a/src/commands/stickers/sticker_list.rs b/src/commands/stickers/sticker_list.rs index 84ae5c1..03f4dce 100644 --- a/src/commands/stickers/sticker_list.rs +++ b/src/commands/stickers/sticker_list.rs @@ -3,14 +3,12 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, request_tokenizer::RequestTokenizer, response_tokenizer::{GenericResponseValue, ResponseAttributes}, types::{StickerType, Uri}, }; -pub struct StickerList; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct StickerListRequest { pub sticker_type: StickerType, @@ -24,6 +22,8 @@ impl StickerListRequest { } impl CommandRequest for StickerListRequest { + type Response = StickerListResponse; + const COMMAND: &'static str = "sticker list"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -68,6 +68,8 @@ impl StickerListResponse { } impl CommandResponse for StickerListResponse { + type Request = StickerListRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: Vec<_> = parts.into_vec()?; if let Some((k, _)) = parts.iter().find(|(k, _)| *k != "sticker") { @@ -104,9 +106,8 @@ impl CommandResponse for StickerListResponse { .collect::, ResponseParserError>>() .map(StickerListResponse) } -} -impl Command for StickerList { - type Request = StickerListRequest; - type Response = StickerListResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for StickerListResponse") + } } diff --git a/src/commands/stickers/sticker_set.rs b/src/commands/stickers/sticker_set.rs index ea7ca73..c17bf67 100644 --- a/src/commands/stickers/sticker_set.rs +++ b/src/commands/stickers/sticker_set.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{StickerType, Uri}, }; -pub struct StickerSet; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct StickerSetRequest { pub sticker_type: StickerType, @@ -28,6 +26,8 @@ impl StickerSetRequest { } impl CommandRequest for StickerSetRequest { + type Response = StickerSetResponse; + const COMMAND: &'static str = "sticker set"; const MIN_ARGS: u32 = 4; const MAX_ARGS: Option = Some(4); @@ -86,8 +86,3 @@ impl CommandRequest for StickerSetRequest { } empty_command_response!(StickerSet); - -impl Command for StickerSet { - type Request = StickerSetRequest; - type Response = StickerSetResponse; -} diff --git a/src/commands/stickers/stickernames.rs b/src/commands/stickers/stickernames.rs index 41ed903..100b9bc 100644 --- a/src/commands/stickers/stickernames.rs +++ b/src/commands/stickers/stickernames.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, ResponseParserError, empty_command_request, multi_item_command_response}, + commands::{ResponseParserError, empty_command_request, multi_item_command_response}, response_tokenizer::expect_property_type, }; -pub struct StickerNames; - empty_command_request!(StickerNames, "stickernames"); multi_item_command_response!(StickerNames, "name", String); - -impl Command for StickerNames { - type Request = StickerNamesRequest; - type Response = StickerNamesResponse; -} diff --git a/src/commands/stickers/stickernamestypes.rs b/src/commands/stickers/stickernamestypes.rs index 72e9e4e..1df1265 100644 --- a/src/commands/stickers/stickernamestypes.rs +++ b/src/commands/stickers/stickernamestypes.rs @@ -3,14 +3,12 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, request_tokenizer::RequestTokenizer, response_tokenizer::{ResponseAttributes, expect_property_type}, types::StickerType, }; -pub struct StickerNamesTypes; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct StickerNamesTypesRequest(Option); @@ -21,6 +19,8 @@ impl StickerNamesTypesRequest { } impl CommandRequest for StickerNamesTypesRequest { + type Response = StickerNamesTypesResponse; + const COMMAND: &'static str = "stickernamestypes"; const MIN_ARGS: u32 = 0; const MAX_ARGS: Option = Some(1); @@ -59,6 +59,8 @@ impl StickerNamesTypesResponse { } impl CommandResponse for StickerNamesTypesResponse { + type Request = StickerNamesTypesRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: Vec<_> = parts.into_vec()?; debug_assert!(parts.len() % 2 == 0); @@ -91,9 +93,10 @@ impl CommandResponse for StickerNamesTypesResponse { Ok(StickerNamesTypesResponse(result)) } -} -impl Command for StickerNamesTypes { - type Request = StickerNamesTypesRequest; - type Response = StickerNamesTypesResponse; + fn serialize(&self) -> Vec { + unimplemented!( + "response serialization is not yet implemented for StickerNamesTypesResponse" + ) + } } diff --git a/src/commands/stickers/stickertypes.rs b/src/commands/stickers/stickertypes.rs index 4a8202b..1ae3168 100644 --- a/src/commands/stickers/stickertypes.rs +++ b/src/commands/stickers/stickertypes.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, ResponseParserError, empty_command_request, multi_item_command_response}, + commands::{ResponseParserError, empty_command_request, multi_item_command_response}, response_tokenizer::expect_property_type, }; -pub struct StickerTypes; - empty_command_request!(StickerTypes, "stickertypes"); multi_item_command_response!(StickerTypes, "stickertype", String); - -impl Command for StickerTypes { - type Request = StickerTypesRequest; - type Response = StickerTypesResponse; -} diff --git a/src/commands/stored_playlists/listplaylist.rs b/src/commands/stored_playlists/listplaylist.rs index ffdbb2f..c091281 100644 --- a/src/commands/stored_playlists/listplaylist.rs +++ b/src/commands/stored_playlists/listplaylist.rs @@ -4,16 +4,13 @@ use serde::{Deserialize, Serialize}; use crate::{ commands::{ - Command, CommandRequest, RequestParserError, ResponseParserError, - multi_item_command_response, + CommandRequest, RequestParserError, ResponseParserError, multi_item_command_response, }, request_tokenizer::RequestTokenizer, response_tokenizer::expect_property_type, types::{PlaylistName, WindowRange}, }; -pub struct ListPlaylist; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ListPlaylistRequest { name: PlaylistName, @@ -27,6 +24,8 @@ impl ListPlaylistRequest { } impl CommandRequest for ListPlaylistRequest { + type Response = ListPlaylistResponse; + const COMMAND: &'static str = "listplaylist"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(2); @@ -61,8 +60,3 @@ impl CommandRequest for ListPlaylistRequest { // NOTE: this is actually supposed to be Vec multi_item_command_response!(ListPlaylist, "file", PathBuf); - -impl Command for ListPlaylist { - type Request = ListPlaylistRequest; - type Response = ListPlaylistResponse; -} diff --git a/src/commands/stored_playlists/listplaylistinfo.rs b/src/commands/stored_playlists/listplaylistinfo.rs index be36f0f..bc9441a 100644 --- a/src/commands/stored_playlists/listplaylistinfo.rs +++ b/src/commands/stored_playlists/listplaylistinfo.rs @@ -1,14 +1,12 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, + commands::{CommandRequest, CommandResponse, RequestParserError, ResponseParserError}, request_tokenizer::RequestTokenizer, response_tokenizer::ResponseAttributes, types::{DbSongInfo, PlaylistName, WindowRange}, }; -pub struct ListPlaylistInfo; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ListPlaylistInfoRequest { name: PlaylistName, @@ -22,6 +20,8 @@ impl ListPlaylistInfoRequest { } impl CommandRequest for ListPlaylistInfoRequest { + type Response = ListPlaylistInfoResponse; + const COMMAND: &'static str = "listplaylistinfo"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(2); @@ -63,12 +63,13 @@ impl ListPlaylistInfoResponse { } impl CommandResponse for ListPlaylistInfoResponse { + type Request = ListPlaylistInfoRequest; + fn parse(_parts: ResponseAttributes<'_>) -> Result { unimplemented!() } -} -impl Command for ListPlaylistInfo { - type Request = ListPlaylistInfoRequest; - type Response = ListPlaylistInfoResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for ListPlaylistInfoResponse") + } } diff --git a/src/commands/stored_playlists/listplaylists.rs b/src/commands/stored_playlists/listplaylists.rs index e9a1cc0..e169115 100644 --- a/src/commands/stored_playlists/listplaylists.rs +++ b/src/commands/stored_playlists/listplaylists.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, empty_command_request}, + commands::{CommandResponse, ResponseParserError, empty_command_request}, response_tokenizer::{ResponseAttributes, get_next_and_parse_property, get_next_property}, types::PlaylistName, }; -pub struct ListPlaylists; - empty_command_request!(ListPlaylists, "listplaylists"); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -36,6 +34,8 @@ impl ListPlaylistsResponseEntry { } impl CommandResponse for ListPlaylistsResponse { + type Request = ListPlaylistsRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let mut parts = parts.into_lazy_vec().into_iter().peekable(); // TODO: count instances of 'playlist' to preallocate @@ -59,11 +59,10 @@ impl CommandResponse for ListPlaylistsResponse { Ok(ListPlaylistsResponse(result)) } -} -impl Command for ListPlaylists { - type Request = ListPlaylistsRequest; - type Response = ListPlaylistsResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for ListPlaylistsResponse") + } } #[cfg(test)] @@ -90,7 +89,7 @@ mod tests { OK "}; - let result = ListPlaylists::parse_raw_response(response.as_bytes()); + let result = ListPlaylistsResponse::parse_raw(response.as_bytes()); assert_eq!( result, diff --git a/src/commands/stored_playlists/load.rs b/src/commands/stored_playlists/load.rs index b6c5254..14eb0f8 100644 --- a/src/commands/stored_playlists/load.rs +++ b/src/commands/stored_playlists/load.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{PlaylistName, SongPosition, WindowRange}, }; -pub struct Load; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct LoadRequest { name: PlaylistName, @@ -30,6 +28,8 @@ impl LoadRequest { } impl CommandRequest for LoadRequest { + type Response = LoadResponse; + const COMMAND: &'static str = "load"; const MIN_ARGS: u32 = 1; const MAX_ARGS: Option = Some(3); @@ -85,8 +85,3 @@ impl CommandRequest for LoadRequest { } empty_command_response!(Load); - -impl Command for Load { - type Request = LoadRequest; - type Response = LoadResponse; -} diff --git a/src/commands/stored_playlists/playlistadd.rs b/src/commands/stored_playlists/playlistadd.rs index 24641c5..608c18d 100644 --- a/src/commands/stored_playlists/playlistadd.rs +++ b/src/commands/stored_playlists/playlistadd.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{PlaylistName, SongPosition, Uri}, }; -pub struct PlaylistAdd; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PlaylistAddRequest { pub playlist_name: PlaylistName, @@ -26,6 +24,8 @@ impl PlaylistAddRequest { } impl CommandRequest for PlaylistAddRequest { + type Response = PlaylistAddResponse; + const COMMAND: &'static str = "playlistadd"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(3); @@ -81,8 +81,3 @@ impl CommandRequest for PlaylistAddRequest { } empty_command_response!(PlaylistAdd); - -impl Command for PlaylistAdd { - type Request = PlaylistAddRequest; - type Response = PlaylistAddResponse; -} diff --git a/src/commands/stored_playlists/playlistclear.rs b/src/commands/stored_playlists/playlistclear.rs index 3868e60..a2b0080 100644 --- a/src/commands/stored_playlists/playlistclear.rs +++ b/src/commands/stored_playlists/playlistclear.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::PlaylistName, }; -pub struct PlaylistClear; - single_item_command_request!(PlaylistClear, "playlistclear", PlaylistName); empty_command_response!(PlaylistClear); - -impl Command for PlaylistClear { - type Request = PlaylistClearRequest; - type Response = PlaylistClearResponse; -} diff --git a/src/commands/stored_playlists/playlistdelete.rs b/src/commands/stored_playlists/playlistdelete.rs index 2fc9122..7835417 100644 --- a/src/commands/stored_playlists/playlistdelete.rs +++ b/src/commands/stored_playlists/playlistdelete.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{OneOrRange, PlaylistName}, }; -pub struct PlaylistDelete; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PlaylistDeleteRequest { pub playlist_name: PlaylistName, @@ -24,6 +22,8 @@ impl PlaylistDeleteRequest { } impl CommandRequest for PlaylistDeleteRequest { + type Response = PlaylistDeleteResponse; + const COMMAND: &'static str = "playlistdelete"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -59,8 +59,3 @@ impl CommandRequest for PlaylistDeleteRequest { } empty_command_response!(PlaylistDelete); - -impl Command for PlaylistDelete { - type Request = PlaylistDeleteRequest; - type Response = PlaylistDeleteResponse; -} diff --git a/src/commands/stored_playlists/playlistlength.rs b/src/commands/stored_playlists/playlistlength.rs index 4f9ae01..a46d6d0 100644 --- a/src/commands/stored_playlists/playlistlength.rs +++ b/src/commands/stored_playlists/playlistlength.rs @@ -3,13 +3,11 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandResponse, ResponseParserError, single_item_command_request}, + commands::{CommandResponse, ResponseParserError, single_item_command_request}, response_tokenizer::{ResponseAttributes, get_and_parse_property}, types::PlaylistName, }; -pub struct PlaylistLength; - single_item_command_request!(PlaylistLength, "playlistlength", PlaylistName); #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -25,6 +23,8 @@ impl PlaylistLengthResponse { } impl CommandResponse for PlaylistLengthResponse { + type Request = PlaylistLengthRequest; + fn parse(parts: ResponseAttributes<'_>) -> Result { let parts: HashMap<_, _> = parts.into_map()?; @@ -33,9 +33,8 @@ impl CommandResponse for PlaylistLengthResponse { Ok(PlaylistLengthResponse { songs, playtime }) } -} -impl Command for PlaylistLength { - type Request = PlaylistLengthRequest; - type Response = PlaylistLengthResponse; + fn serialize(&self) -> Vec { + unimplemented!("response serialization is not yet implemented for PlaylistLengthResponse") + } } diff --git a/src/commands/stored_playlists/playlistmove.rs b/src/commands/stored_playlists/playlistmove.rs index fae84c3..3fe7ea4 100644 --- a/src/commands/stored_playlists/playlistmove.rs +++ b/src/commands/stored_playlists/playlistmove.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{OneOrRange, PlaylistName, SongPosition}, }; -pub struct PlaylistMove; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PlaylistMoveRequest { pub playlist_name: PlaylistName, @@ -26,6 +24,8 @@ impl PlaylistMoveRequest { } impl CommandRequest for PlaylistMoveRequest { + type Response = PlaylistMoveResponse; + const COMMAND: &'static str = "playlistmove"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(3); @@ -81,8 +81,3 @@ impl CommandRequest for PlaylistMoveRequest { } empty_command_response!(PlaylistMove); - -impl Command for PlaylistMove { - type Request = PlaylistMoveRequest; - type Response = PlaylistMoveResponse; -} diff --git a/src/commands/stored_playlists/rename.rs b/src/commands/stored_playlists/rename.rs index 1b4bc83..609a2a1 100644 --- a/src/commands/stored_playlists/rename.rs +++ b/src/commands/stored_playlists/rename.rs @@ -1,12 +1,10 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, }; -pub struct Rename; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct RenameRequest { pub old_name: String, @@ -20,6 +18,8 @@ impl RenameRequest { } impl CommandRequest for RenameRequest { + type Response = RenameResponse; + const COMMAND: &'static str = "rename"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(2); @@ -46,8 +46,3 @@ impl CommandRequest for RenameRequest { } empty_command_response!(Rename); - -impl Command for Rename { - type Request = RenameRequest; - type Response = RenameResponse; -} diff --git a/src/commands/stored_playlists/rm.rs b/src/commands/stored_playlists/rm.rs index 86793d7..3e97148 100644 --- a/src/commands/stored_playlists/rm.rs +++ b/src/commands/stored_playlists/rm.rs @@ -1,15 +1,8 @@ use crate::{ - commands::{Command, empty_command_response, single_item_command_request}, + commands::{empty_command_response, single_item_command_request}, types::PlaylistName, }; -pub struct Rm; - single_item_command_request!(Rm, "rm", PlaylistName); empty_command_response!(Rm); - -impl Command for Rm { - type Request = RmRequest; - type Response = RmResponse; -} diff --git a/src/commands/stored_playlists/save.rs b/src/commands/stored_playlists/save.rs index 1407181..fac454c 100644 --- a/src/commands/stored_playlists/save.rs +++ b/src/commands/stored_playlists/save.rs @@ -1,13 +1,11 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::{PlaylistName, SaveMode}, }; -pub struct Save; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SaveRequest { pub playlist_name: PlaylistName, @@ -24,6 +22,8 @@ impl SaveRequest { } impl CommandRequest for SaveRequest { + type Response = SaveResponse; + const COMMAND: &'static str = "save"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(3); @@ -63,8 +63,3 @@ impl CommandRequest for SaveRequest { } empty_command_response!(Save); - -impl Command for Save { - type Request = SaveRequest; - type Response = SaveResponse; -} diff --git a/src/commands/stored_playlists/searchplaylist.rs b/src/commands/stored_playlists/searchplaylist.rs index e88e833..6faedf7 100644 --- a/src/commands/stored_playlists/searchplaylist.rs +++ b/src/commands/stored_playlists/searchplaylist.rs @@ -1,14 +1,12 @@ use serde::{Deserialize, Serialize}; use crate::{ - commands::{Command, CommandRequest, RequestParserError, empty_command_response}, + commands::{CommandRequest, RequestParserError, empty_command_response}, filter::Filter, request_tokenizer::RequestTokenizer, types::{PlaylistName, WindowRange}, }; -pub struct SearchPlaylist; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SearchPlaylistRequest { pub name: PlaylistName, @@ -27,6 +25,8 @@ impl SearchPlaylistRequest { } impl CommandRequest for SearchPlaylistRequest { + type Response = SearchPlaylistResponse; + const COMMAND: &'static str = "searchplaylist"; const MIN_ARGS: u32 = 2; const MAX_ARGS: Option = Some(3); @@ -80,8 +80,3 @@ impl CommandRequest for SearchPlaylistRequest { } empty_command_response!(SearchPlaylist); - -impl Command for SearchPlaylist { - type Request = SearchPlaylistRequest; - type Response = SearchPlaylistResponse; -}