]> git.lizzy.rs Git - rust.git/blob - src/liballoc/tests/lib.rs
Simplify SaveHandler trait
[rust.git] / src / liballoc / tests / lib.rs
1 #![feature(allocator_api)]
2 #![feature(box_syntax)]
3 #![feature(drain_filter)]
4 #![feature(exact_size_is_empty)]
5 #![feature(option_flattening)]
6 #![feature(pattern)]
7 #![feature(repeat_generic_slice)]
8 #![feature(trusted_len)]
9 #![feature(try_reserve)]
10 #![feature(unboxed_closures)]
11 #![deny(rust_2018_idioms)]
12
13 use std::hash::{Hash, Hasher};
14 use std::collections::hash_map::DefaultHasher;
15
16 mod arc;
17 mod binary_heap;
18 mod btree;
19 mod cow_str;
20 mod fmt;
21 mod heap;
22 mod linked_list;
23 mod rc;
24 mod slice;
25 mod str;
26 mod string;
27 mod vec_deque;
28 mod vec;
29
30 fn hash<T: Hash>(t: &T) -> u64 {
31     let mut s = DefaultHasher::new();
32     t.hash(&mut s);
33     s.finish()
34 }
35
36 // FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
37 // See https://github.com/kripken/emscripten-fastcomp/issues/169
38 #[cfg(not(target_os = "emscripten"))]
39 #[test]
40 fn test_boxed_hasher() {
41     let ordinary_hash = hash(&5u32);
42
43     let mut hasher_1 = Box::new(DefaultHasher::new());
44     5u32.hash(&mut hasher_1);
45     assert_eq!(ordinary_hash, hasher_1.finish());
46
47     let mut hasher_2 = Box::new(DefaultHasher::new()) as Box<dyn Hasher>;
48     5u32.hash(&mut hasher_2);
49     assert_eq!(ordinary_hash, hasher_2.finish());
50 }