memory_cache_rust/bloom/
hasher.rs

1use std::any::{Any, TypeId};
2
3// pub type KeyHash<T> = Box<dyn FnMut(T) -> (u64, i64)>;
4
5
6
7pub fn value_to_int<T: 'static>(key: T) -> i64 {
8    if is_cast::<T, u64>(&key) {
9        let  v = unsafe { std::mem::transmute::< & T,&u64,>(&key) };
10        return *v as i64
11    }
12    panic!("")
13    /*   if equals::<T, u64>() {
14           let value = cast_ref::<_, u64>(&key).unwrap();
15           return *value as i64;
16       }
17
18       if equals::<T, usize>() {
19           let value = cast_ref::<_, usize>(&key).unwrap();
20           return *value as i64;
21       }
22
23
24       if equals::<T, i64>() {
25           let value = cast_ref::<_, i64>(&key).unwrap();
26           return *value as i64;
27       }
28
29
30       if equals::<T, i32>() {
31           let value = cast_ref::<_, i32>(&key).unwrap();
32
33           return *value as i64;
34       }
35
36       if equals::<T, u8>() {
37           let value = cast_ref::<_, u8>(&key).unwrap();
38           return *value as i64;
39       }
40       if equals::<T, u16>() {
41           let value = cast_ref::<_, u16>(&key).unwrap();
42
43           return *value as i64;
44       }
45       if equals::<T, u32>() {
46           let value = cast_ref::<_, u32>(&key).unwrap();
47
48           return *value as i64;
49       }
50       if equals::<T, i16>() {
51           let value = cast_ref::<_, i16>(&key).unwrap();
52
53           return *value as i64;
54       }
55       panic!("! value type not supported")*/
56}
57
58fn is_string<T: ?Sized + Any>(_s: &T) -> bool {
59    TypeId::of::<String>() == TypeId::of::<T>()
60}
61
62pub fn is_cast<T: ?Sized + Any, V: 'static>(_s: &T) -> bool {
63    TypeId::of::<V>() == TypeId::of::<T>()
64}
65
66/*pub fn equals<U:  ?Sized + Any, V: 'static>() -> bool {
67    TypeId::of::<U>() == TypeId::of::<V>()
68}
69
70pub fn cast_ref<U:  ?Sized + Any, V: 'static>(u: &U) -> Option<&V> {
71    if equals::<U, V>() {
72        Some(unsafe { std::mem::transmute::<&U, &V>(u) })
73    } else {
74        None
75    }
76}
77
78pub fn cast_mut<U: 'static, V: 'static>(u: &mut U) -> Option<&mut V> {
79    if equals::<U, V>() {
80        Some(unsafe { std::mem::transmute::<&mut U, &mut V>(u) })
81    } else {
82        None
83    }
84}
85*/
86#[cfg(test)]
87mod tests {
88    
89
90    #[test]
91    fn test_hash() {
92
93    }
94}