From 7c2f9311bf166aab7300bc63d407d30ce1fe586b Mon Sep 17 00:00:00 2001 From: Jordan Bracco Date: Fri, 12 Nov 2021 18:19:13 +0100 Subject: treebitmap_nif: split nibbles/addrs in modules --- native/treebitmap_nif/src/nibbles.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 native/treebitmap_nif/src/nibbles.rs (limited to 'native/treebitmap_nif/src/nibbles.rs') diff --git a/native/treebitmap_nif/src/nibbles.rs b/native/treebitmap_nif/src/nibbles.rs new file mode 100644 index 0000000..ca1939b --- /dev/null +++ b/native/treebitmap_nif/src/nibbles.rs @@ -0,0 +1,32 @@ +pub struct NibblesV4 { + pub n: [u8; 8], +} +pub struct NibblesV6 { + pub n: [u8; 32], +} + +pub enum Nibbles { + V4(NibblesV4), + V6(NibblesV6), +} + +impl AsRef<[u8]> for Nibbles { + fn as_ref(&self) -> &[u8] { + match self { + Nibbles::V4(nib4) => nib4.as_ref(), + Nibbles::V6(nib6) => nib6.as_ref(), + } + } +} + +impl AsRef<[u8]> for NibblesV4 { + fn as_ref(&self) -> &[u8] { + &self.n + } +} + +impl AsRef<[u8]> for NibblesV6 { + fn as_ref(&self) -> &[u8] { + &self.n + } +} -- cgit v1.2.3