aboutsummaryrefslogtreecommitdiff
path: root/native/treebitmap_nif/src/nibbles.rs
diff options
context:
space:
mode:
authorJordan Bracco <href@random.sh>2021-11-12 18:19:13 +0100
committerJordan Bracco <href@random.sh>2021-11-12 18:19:13 +0100
commit7c2f9311bf166aab7300bc63d407d30ce1fe586b (patch)
tree909c9f90664383c8d4a1e7827ba675c55a21cf19 /native/treebitmap_nif/src/nibbles.rs
parentImprove API (diff)
treebitmap_nif: split nibbles/addrs in modulesHEADmain
Diffstat (limited to '')
-rw-r--r--native/treebitmap_nif/src/nibbles.rs32
1 files changed, 32 insertions, 0 deletions
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
+ }
+}