1use crate::{
4 client::resp::{
5 handlers::{MixedResponseResponse, OkResponse, RespMapResponse, ResponseHandler, Tracks},
6 respmap_handlers::ListallResponse,
7 },
8 DatabaseVersion,
9};
10
11#[derive(Copy, Clone)]
12pub struct Stats;
13#[derive(Copy, Clone)]
14pub struct Status;
15
16#[derive(Copy, Clone)]
17pub struct Setvol(pub u32);
18#[derive(Copy, Clone)]
19pub struct Repeat(pub bool);
20#[derive(Copy, Clone)]
21pub struct Random(pub bool);
22#[derive(Copy, Clone)]
23pub struct Consume(pub bool);
24
25#[derive(Copy, Clone)]
26pub struct PlayId(pub u32);
27#[derive(Copy, Clone)]
28pub struct QueueClear;
29#[derive(Copy, Clone)]
30pub struct QueueAdd<'a>(pub &'a str);
31
32#[derive(Copy, Clone)]
33pub struct Search<'a>(pub Option<&'a str>);
34#[derive(Copy, Clone)]
35pub struct PlaylistInfo;
36
37#[derive(Copy, Clone)]
38pub struct Stop;
39#[derive(Copy, Clone)]
40pub struct PlayPause(pub bool);
41#[derive(Copy, Clone)]
42pub struct Next;
43#[derive(Copy, Clone)]
44pub struct Prev;
45
46#[derive(Copy, Clone)]
47pub struct Rescan<'a>(pub Option<&'a str>);
48#[derive(Copy, Clone)]
49pub struct Update<'a>(pub Option<&'a str>);
50
51#[derive(Copy, Clone)]
52pub struct Idle;
53#[derive(Copy, Clone)]
54pub struct NoIdle;
55
56#[derive(Copy, Clone)]
57pub struct Listall<'a>(pub Option<&'a str>);
58#[derive(Copy, Clone)]
59pub struct ListallInfo<'a>(pub Option<&'a str>);
60
61pub trait MpdCmd {
62 const CMD: &'static str;
64 type Handler: ResponseHandler;
66 fn argument(&self) -> Option<String> {
68 None
69 }
70 fn to_cmdline(&self) -> String {
72 if let Some(arg) = self.argument() {
73 format!("{} \"{}\"\n", Self::CMD, arg)
74 } else {
75 format!("{}\n", Self::CMD)
76 }
77 }
78}
79
80impl<'a> MpdCmd for ListallInfo<'a> {
81 const CMD: &'static str = "listallinfo";
82 type Handler = MixedResponseResponse;
83
84 fn argument(&self) -> Option<String> {
85 self.0.map(ToString::to_string)
86 }
87}
88
89impl<'a> MpdCmd for QueueAdd<'a> {
90 const CMD: &'static str = "add";
91 type Handler = OkResponse;
92
93 fn argument(&self) -> Option<String> {
94 Some(self.0.to_string())
95 }
96}
97
98impl<'a> MpdCmd for Listall<'a> {
99 const CMD: &'static str = "listall";
100 type Handler = RespMapResponse<ListallResponse>;
101
102 fn argument(&self) -> Option<String> {
103 self.0.map(ToString::to_string)
104 }
105}
106
107impl<'a> MpdCmd for Update<'a> {
108 const CMD: &'static str = "update";
109 type Handler = RespMapResponse<DatabaseVersion>;
110
111 fn argument(&self) -> Option<String> {
112 self.0.map(ToString::to_string)
113 }
114}
115
116impl<'a> MpdCmd for Rescan<'a> {
117 const CMD: &'static str = "rescan";
118 type Handler = RespMapResponse<DatabaseVersion>;
119
120 fn argument(&self) -> Option<String> {
121 self.0.map(ToString::to_string)
122 }
123}
124
125impl<'a> MpdCmd for Search<'a> {
126 const CMD: &'static str = "search";
127 type Handler = Tracks;
128 fn argument(&self) -> Option<String> {
129 self.0.map(ToString::to_string)
130 }
131}
132
133impl MpdCmd for PlaylistInfo {
134 const CMD: &'static str = "playlistinfo";
135 type Handler = Tracks;
136}
137
138impl MpdCmd for Repeat {
139 const CMD: &'static str = "repeat";
140 type Handler = OkResponse;
141 fn argument(&self) -> Option<String> {
142 Some((self.0 as u32).to_string())
143 }
144}
145
146impl MpdCmd for Random {
147 const CMD: &'static str = "random";
148 type Handler = OkResponse;
149 fn argument(&self) -> Option<String> {
150 Some((self.0 as u32).to_string())
151 }
152}
153
154impl MpdCmd for Consume {
155 const CMD: &'static str = "consume";
156 type Handler = OkResponse;
157 fn argument(&self) -> Option<String> {
158 Some((self.0 as u32).to_string())
159 }
160}
161
162impl MpdCmd for PlayPause {
163 const CMD: &'static str = "pause";
164 type Handler = OkResponse;
165 fn argument(&self) -> Option<String> {
166 Some((self.0 as u32).to_string())
167 }
168}
169
170impl MpdCmd for Next {
171 const CMD: &'static str = "next";
172 type Handler = OkResponse;
173}
174impl MpdCmd for Prev {
175 const CMD: &'static str = "prev";
176 type Handler = OkResponse;
177}
178
179impl MpdCmd for QueueClear {
180 const CMD: &'static str = "clear";
181 type Handler = OkResponse;
182}
183
184impl MpdCmd for NoIdle {
185 const CMD: &'static str = "noidle";
186 type Handler = OkResponse;
187}
188
189impl MpdCmd for Idle {
190 const CMD: &'static str = "idle";
191 type Handler = RespMapResponse<crate::Subsystem>;
192}
193
194impl MpdCmd for Stats {
195 const CMD: &'static str = "stats";
196 type Handler = RespMapResponse<crate::Stats>;
197}
198
199impl MpdCmd for Status {
200 const CMD: &'static str = "status";
201 type Handler = RespMapResponse<crate::Status>;
202}
203
204impl MpdCmd for Setvol {
205 const CMD: &'static str = "setvol";
206 type Handler = OkResponse;
207
208 fn argument(&self) -> Option<String> {
209 Some(self.0.to_string())
210 }
211}
212
213impl MpdCmd for Stop {
214 const CMD: &'static str = "stop";
215 type Handler = OkResponse;
216}
217
218impl MpdCmd for PlayId {
219 const CMD: &'static str = "playid";
220 type Handler = OkResponse;
221
222 fn argument(&self) -> Option<String> {
223 Some(self.0.to_string())
224 }
225}