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