lib.rs 1.3 KB
Newer Older
1
#![feature(allocator_api)]
2
#![feature(box_syntax)]
A
Alexis Beingessner 已提交
3
#![feature(drain_filter)]
4
#![feature(exact_size_is_empty)]
5
#![feature(map_first_last)]
6
#![feature(new_uninit)]
7
#![feature(pattern)]
8
#![feature(trusted_len)]
9
#![feature(try_reserve)]
10
#![feature(unboxed_closures)]
11
#![feature(associated_type_bounds)]
12 13
#![feature(binary_heap_into_iter_sorted)]
#![feature(binary_heap_drain_sorted)]
S
Simonas Kazlauskas 已提交
14

15
use std::collections::hash_map::DefaultHasher;
M
Mark Rousskov 已提交
16
use std::hash::{Hash, Hasher};
17

18
mod arc;
19
mod binary_heap;
20
mod boxed;
21
mod btree;
22
mod cow_str;
23
mod fmt;
24
mod heap;
25
mod linked_list;
26
mod rc;
27 28 29 30
mod slice;
mod str;
mod string;
mod vec;
M
Mark Rousskov 已提交
31
mod vec_deque;
32 33

fn hash<T: Hash>(t: &T) -> u64 {
34
    let mut s = DefaultHasher::new();
35 36 37
    t.hash(&mut s);
    s.finish()
}
38

39 40 41
// FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
// See https://github.com/kripken/emscripten-fastcomp/issues/169
#[cfg(not(target_os = "emscripten"))]
42 43 44 45 46 47 48 49
#[test]
fn test_boxed_hasher() {
    let ordinary_hash = hash(&5u32);

    let mut hasher_1 = Box::new(DefaultHasher::new());
    5u32.hash(&mut hasher_1);
    assert_eq!(ordinary_hash, hasher_1.finish());

T
Tatsuyuki Ishi 已提交
50
    let mut hasher_2 = Box::new(DefaultHasher::new()) as Box<dyn Hasher>;
51 52 53
    5u32.hash(&mut hasher_2);
    assert_eq!(ordinary_hash, hasher_2.finish());
}