diff options
author | Jordan Bracco <href@random.sh> | 2021-11-12 16:12:26 +0100 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2021-11-12 16:12:26 +0100 |
commit | df4d0399133a7ab3a40d5bde05c642875d1d4c14 (patch) | |
tree | 908c178514e08d6e8060ab69016d01d78113d01a /native | |
parent | improve rust.. (diff) |
Rename to RoutingTable, improvements
Diffstat (limited to 'native')
-rw-r--r-- | native/treebitmap_nif/src/lib.rs | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/native/treebitmap_nif/src/lib.rs b/native/treebitmap_nif/src/lib.rs index 5d1821b..58859e7 100644 --- a/native/treebitmap_nif/src/lib.rs +++ b/native/treebitmap_nif/src/lib.rs @@ -17,34 +17,10 @@ mod atoms { } } -trait Address { +trait Maskable { fn mask(self, masklen: u32) -> Self; } -#[derive(NifUntaggedEnum, Copy, Clone)] -enum AddrTuple { - V4(TupleV4), - V6(TupleV6) -} - -impl Address for AddrTuple { - fn mask(self, masklen: u32) -> Self { - match self { - AddrTuple::V4(tuple_v4) => AddrTuple::V4(tuple_v4.mask(masklen)), - AddrTuple::V6(tuple_v6) => AddrTuple::V6(tuple_v6.mask(masklen)) - } - } -} - -#[derive(Debug, NifRecord, Copy, Clone)] -#[tag = "inet4"] -struct TupleV4 { - pub a: u8, - pub b: u8, - pub c: u8, - pub d: u8 -} - struct NibblesV4 { pub n: [u8; 8]} struct NibblesV6 { pub n: [u8; 32]} @@ -71,6 +47,31 @@ impl AsRef<[u8]> for NibblesV6 { } } + +#[derive(NifUntaggedEnum, Copy, Clone)] +enum AddrTuple { + V4(TupleV4), + V6(TupleV6) +} + +impl Maskable for AddrTuple { + fn mask(self, masklen: u32) -> Self { + match self { + AddrTuple::V4(tuple_v4) => AddrTuple::V4(tuple_v4.mask(masklen)), + AddrTuple::V6(tuple_v6) => AddrTuple::V6(tuple_v6.mask(masklen)) + } + } +} + +#[derive(Debug, NifRecord, Copy, Clone)] +#[tag = "inet4"] +struct TupleV4 { + pub a: u8, + pub b: u8, + pub c: u8, + pub d: u8 +} + impl TupleV4 { pub fn from(num: u32) -> Self { TupleV4 { @@ -86,7 +87,7 @@ impl TupleV4 { } } -impl Address for TupleV4 { +impl Maskable for TupleV4 { fn mask(self, masklen: u32) -> Self { debug_assert!(masklen <= 32); let ip = u32::from(self); @@ -186,7 +187,7 @@ impl TupleV6 { } -impl Address for TupleV6 { +impl Maskable for TupleV6 { fn mask(self, masklen: u32) -> Self { debug_assert!(masklen <= 128); @@ -312,7 +313,7 @@ fn memory<'a>( make_tuple(env, &[nodes.encode(env), results.encode(env)]) } -rustler::init!("Elixir.TreeBitmap.NIF", +rustler::init!("Elixir.RoutingTable.TreeBitmap", [new, new_with_capacity, length, |