Skip to content

Commit

Permalink
Add hash
Browse files Browse the repository at this point in the history
  • Loading branch information
vaIgarashi committed Nov 11, 2019
1 parent 31cfb46 commit ae4f04a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 26 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Eui48, u8, U1> = 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<Eui64, u8, U1> = FnvIndexMap::new();
fnv_index_map.insert(eui64, 1);

assert_eq!(1, *fnv_index_map.get(&eui64).unwrap())
}

0 comments on commit ae4f04a

Please sign in to comment.