4
4
//! (e.g. [`TimeZone`](../offset/trait.TimeZone.html)),
5
5
//! but can be also used for the simpler date and time handling.
6
6
7
+ use core:: hash:: { Hash , Hasher } ;
7
8
use core:: ops:: RangeInclusive ;
8
9
9
10
use crate :: Weekday ;
@@ -212,7 +213,6 @@ impl PartialEq for NaiveWeek {
212
213
}
213
214
}
214
215
215
- use core:: hash:: { Hash , Hasher } ;
216
216
impl Hash for NaiveWeek {
217
217
fn hash < H : Hasher > ( & self , state : & mut H ) {
218
218
self . first_day ( ) . hash ( state) ;
@@ -300,6 +300,7 @@ mod test {
300
300
let b =
301
301
NaiveWeek { date : NaiveDate :: from_ymd_opt ( 2025 , 4 , 4 ) . unwrap ( ) , start : Weekday :: Mon } ;
302
302
assert_eq ! ( a, b) ;
303
+
303
304
let c =
304
305
NaiveWeek { date : NaiveDate :: from_ymd_opt ( 2025 , 4 , 3 ) . unwrap ( ) , start : Weekday :: Sun } ;
305
306
assert_ne ! ( a, c) ;
@@ -308,21 +309,25 @@ mod test {
308
309
309
310
#[ test]
310
311
fn test_naiveweek_hash ( ) {
311
- let mut hasher = DefaultHasher :: default ( ) ;
312
312
let a =
313
313
NaiveWeek { date : NaiveDate :: from_ymd_opt ( 2025 , 4 , 3 ) . unwrap ( ) , start : Weekday :: Mon } ;
314
314
let b =
315
315
NaiveWeek { date : NaiveDate :: from_ymd_opt ( 2025 , 4 , 4 ) . unwrap ( ) , start : Weekday :: Mon } ;
316
316
let c =
317
317
NaiveWeek { date : NaiveDate :: from_ymd_opt ( 2025 , 4 , 3 ) . unwrap ( ) , start : Weekday :: Sun } ;
318
+
319
+ let mut hasher = DefaultHasher :: default ( ) ;
318
320
a. hash ( & mut hasher) ;
319
321
let a_hash = hasher. finish ( ) ;
322
+
320
323
hasher = DefaultHasher :: default ( ) ;
321
324
b. hash ( & mut hasher) ;
322
325
let b_hash = hasher. finish ( ) ;
326
+
323
327
hasher = DefaultHasher :: default ( ) ;
324
328
c. hash ( & mut hasher) ;
325
329
let c_hash = hasher. finish ( ) ;
330
+
326
331
assert_eq ! ( a_hash, b_hash) ;
327
332
assert_ne ! ( b_hash, c_hash) ;
328
333
assert_ne ! ( a_hash, c_hash) ;
0 commit comments