diff --git a/Cargo.toml b/Cargo.toml index 02c3f8f..fbdead1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,8 @@ name = "eui" [dependencies] heapless = "0.5" serde = { version = "1.0", default-features = false, optional = true } +hash32 = "0.1" +hash32-derive = "0.1" [dev-dependencies] serde_test = "1.0" diff --git a/src/lib.rs b/src/lib.rs index 7572883..f21b37f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,9 +25,9 @@ use heapless::{String, Vec}; const HEX_CHARS: &[u8] = b"0123456789abcdef"; -#[derive(Eq, PartialEq, Copy, Clone, Debug)] +#[derive(Eq, PartialEq, Copy, Clone, Debug, hash32_derive::Hash32)] pub struct Eui48([u8; 6]); -#[derive(Eq, PartialEq, Copy, Clone, Debug)] +#[derive(Eq, PartialEq, Copy, Clone, Debug, hash32_derive::Hash32)] pub struct Eui64([u8; 8]); macro_rules! to_hex_string { @@ -156,3 +156,27 @@ fn test_u64_from_eui64() { let eui64 = Eui64::from(5583992946972634863); assert_eq!(u64::from(eui64), 5583992946972634863); } + +#[test] +fn test_hash_eui48() { + use heapless::FnvIndexMap; + + let eui48 = Eui48::from(85204980412143); + + let mut fnv_index_map: FnvIndexMap = FnvIndexMap::new(); + fnv_index_map.insert(eui48, 1); + + assert_eq!(1, *fnv_index_map.get(&eui48).unwrap()) +} + +#[test] +fn test_hash_eui64() { + use heapless::FnvIndexMap; + + let eui64 = Eui64::from(5583992946972634863); + + let mut fnv_index_map: FnvIndexMap = FnvIndexMap::new(); + fnv_index_map.insert(eui64, 1); + + assert_eq!(1, *fnv_index_map.get(&eui64).unwrap()) +}