@@ -9,7 +9,7 @@ extern crate serde_derive;
9
9
10
10
use config:: * ;
11
11
use float_cmp:: ApproxEqUlps ;
12
- use std:: collections:: HashMap ;
12
+ use std:: collections:: { HashMap , HashSet } ;
13
13
14
14
#[ derive( Debug , Deserialize ) ]
15
15
struct Place {
@@ -226,3 +226,42 @@ fn test_enum() {
226
226
assert_eq ! ( s. diodes[ "blue" ] , Diode :: Blinking ( 300 , 700 ) ) ;
227
227
assert_eq ! ( s. diodes[ "white" ] , Diode :: Pattern { name: "christmas" . into( ) , inifinite: true , } ) ;
228
228
}
229
+
230
+ #[ test]
231
+ fn test_enum_key ( ) {
232
+ #[ derive( Debug , Deserialize , PartialEq , Eq , Hash ) ]
233
+ enum Quark {
234
+ Up ,
235
+ Down ,
236
+ Strange ,
237
+ Charm ,
238
+ Bottom ,
239
+ Top ,
240
+ }
241
+
242
+ #[ derive( Debug , Deserialize ) ]
243
+ struct Settings {
244
+ proton : HashMap < Quark , usize > ,
245
+ // Just to make sure that set keys work too.
246
+ quarks : HashSet < Quark > ,
247
+ }
248
+
249
+ let c = make ( ) ;
250
+ let s: Settings = c. try_into ( ) . unwrap ( ) ;
251
+
252
+ assert_eq ! ( s. proton[ & Quark :: Up ] , 2 ) ;
253
+ assert_eq ! ( s. quarks. len( ) , 6 ) ;
254
+ }
255
+
256
+ #[ test]
257
+ fn test_int_key ( ) {
258
+ #[ derive( Debug , Deserialize , PartialEq ) ]
259
+ struct Settings {
260
+ divisors : HashMap < u32 , u32 > ,
261
+ }
262
+
263
+ let c = make ( ) ;
264
+ let s: Settings = c. try_into ( ) . unwrap ( ) ;
265
+ assert_eq ! ( s. divisors[ & 4 ] , 3 ) ;
266
+ assert_eq ! ( s. divisors. len( ) , 4 ) ;
267
+ }
0 commit comments