File tree 1 file changed +21
-0
lines changed
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,26 @@ fn possible_backends() -> Vec<&'static str> {
173
173
audio_backend:: BACKENDS . iter ( ) . map ( |b| b. 0 ) . collect ( )
174
174
}
175
175
176
+ fn deserialize_backend < ' de , D > ( de : D ) -> Result < Option < String > , D :: Error >
177
+ where
178
+ D : Deserializer < ' de > ,
179
+ {
180
+ let backend = String :: deserialize ( de) ?;
181
+ let possible_backends = possible_backends ( ) ;
182
+ if possible_backends. contains ( & backend. as_str ( ) ) {
183
+ Ok ( Some ( backend) )
184
+ } else {
185
+ Err ( de:: Error :: invalid_value (
186
+ Unexpected :: Str ( & backend) ,
187
+ & format ! (
188
+ "a valid backend (available: {})" ,
189
+ possible_backends. join( ", " )
190
+ )
191
+ . as_str ( ) ,
192
+ ) )
193
+ }
194
+ }
195
+
176
196
fn number_or_string < ' de , D > ( de : D ) -> Result < Option < u8 > , D :: Error >
177
197
where
178
198
D : Deserializer < ' de > ,
@@ -265,6 +285,7 @@ pub struct SharedConfigValues {
265
285
266
286
/// The audio backend to use
267
287
#[ arg( long, short, value_parser = possible_backends( ) ) ]
288
+ #[ serde( deserialize_with = "deserialize_backend" ) ]
268
289
backend : Option < String > ,
269
290
270
291
/// The volume controller to use
You can’t perform that action at this time.
0 commit comments