| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/; |
| 2 | |
| 3 | use craterust-analyzer cargo udevrs 0.4.0 crate/::{hwdbrust-analyzer cargo udevrs 0.4.0 hwdb/, Errorrust-analyzer cargo udevrs 0.4.0 error/Error#, Resultrust-analyzer cargo udevrs 0.4.0 error/Result#}; |
| 4 | |
| 5 | /// Trie node in the hardware database. |
| 6 | #[repr(C, packed(8))] |
| 7 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 8 | pub struct TrieNoderust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode# { |
| 9 | prefix_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#prefix_off.: u64, |
| 10 | children_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#children_count.: u8, |
| 11 | _paddingrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#_padding.: [u8; 7], |
| 12 | values_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#values_count.: u64, |
| 13 | } |
| 14 | |
| 15 | impl TrieNoderust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode# { |
| 16 | /// Creates a new [TrieNode]. |
| 17 | pub const fn newrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]new().() -> Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode] { |
| 18 | Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode] { |
| 19 | prefix_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#prefix_off.: 0, |
| 20 | children_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#children_count.: 0, |
| 21 | _paddingrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#_padding.: [0u8; 7], |
| 22 | values_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#values_count.: 0, |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | /// Gets the length of the encoded [TrieNode]. |
| 27 | pub fn lenrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]len().(&self) -> usize { |
| 28 | hwdbrust-analyzer cargo udevrs 0.4.0 hwdb/::node_sizerust-analyzer cargo udevrs 0.4.0 hwdb/node_size().() |
| 29 | } |
| 30 | |
| 31 | /// Gets whether the [TrieNode] is empty. |
| 32 | pub const fn is_emptyrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]is_empty().(&self) -> bool { |
| 33 | self.children_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#children_count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 && self.values_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#values_count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().0 |
| 34 | } |
| 35 | |
| 36 | /// Gets the prefix of the lookup string, shared by all children. |
| 37 | pub const fn prefix_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]prefix_off().(&self) -> u64 { |
| 38 | self.prefix_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#prefix_off. |
| 39 | } |
| 40 | |
| 41 | /// Sets the prefix of the lookup string, shared by all children. |
| 42 | pub fn set_prefix_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]set_prefix_off().(&mut self, val: u64) { |
| 43 | self.prefix_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#prefix_off. = val; |
| 44 | } |
| 45 | |
| 46 | /// Builder function that sets the prefix of the lookup string, shared by all children. |
| 47 | pub fn with_prefix_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]with_prefix_off().(mut self, val: u64) -> Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode] { |
| 48 | self.set_prefix_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]set_prefix_off().(val); |
| 49 | self |
| 50 | } |
| 51 | |
| 52 | /// Gets the size of children entry array appended to the node. |
| 53 | pub const fn children_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]children_count().(&self) -> u8 { |
| 54 | self.children_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#children_count. |
| 55 | } |
| 56 | |
| 57 | /// Sets the size of children entry array appended to the node. |
| 58 | pub fn set_children_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]set_children_count().(&mut self, val: u8) { |
| 59 | self.children_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#children_count. = val; |
| 60 | } |
| 61 | |
| 62 | /// Builder function that sets the size of children entry array appended to the node. |
| 63 | pub fn with_children_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]with_children_count().(mut self, val: u8) -> Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode] { |
| 64 | self.set_children_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]set_children_count().(val); |
| 65 | self |
| 66 | } |
| 67 | |
| 68 | /// Gets the size of value entry array appended to the node. |
| 69 | pub const fn values_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]values_count().(&self) -> u64 { |
| 70 | self.values_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#values_count. |
| 71 | } |
| 72 | |
| 73 | /// Sets the size of value entry array appended to the node. |
| 74 | pub fn set_values_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]set_values_count().(&mut self, val: u64) { |
| 75 | self.values_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#values_count. = val; |
| 76 | } |
| 77 | |
| 78 | /// Builder function that sets the size of value entry array appended to the node. |
| 79 | pub fn with_values_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]with_values_count().(mut self, val: u64) -> Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode] { |
| 80 | self.set_values_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode]set_values_count().(val); |
| 81 | self |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&[u8]> for TrieNoderust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode# { |
| 86 | type Errorrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode][`TryFrom<&[u8]>`]Error# = Errorrust-analyzer cargo udevrs 0.4.0 error/Error#; |
| 87 | |
| 88 | fn try_fromrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode][`TryFrom<&[u8]>`]try_from().(val: &[u8]) -> Resultrust-analyzer cargo udevrs 0.4.0 error/Result#<Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode][`TryFrom<&[u8]>`]> { |
| 89 | if val.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode][`TryFrom<&[u8]>`]>() { |
| 90 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo udevrs 0.4.0 error/Error#::InvalidLenrust-analyzer cargo udevrs 0.4.0 error/Error#InvalidLen#(val.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())) |
| 91 | } else { |
| 92 | let mut idx = 0usize; |
| 93 | |
| 94 | let prefix_off = u64::from_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]from_le_bytes().(val[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().8]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#try_into().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/Try#branch().); |
| 95 | idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<u64>(); |
| 96 | |
| 97 | let children_count = val[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 98 | let _padding = [0u8; 7]; |
| 99 | |
| 100 | // skip past the children count + padding |
| 101 | idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().8; |
| 102 | |
| 103 | let values_count = u64::from_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]from_le_bytes().( |
| 104 | val.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(idx..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().8) |
| 105 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(Errorrust-analyzer cargo udevrs 0.4.0 error/Error#::InvalidLenrust-analyzer cargo udevrs 0.4.0 error/Error#InvalidLen#(val.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 106 | .try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#try_into().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/Try#branch()., |
| 107 | ); |
| 108 | |
| 109 | if values_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().64 { |
| 110 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo udevrs 0.4.0 error/Error#::InvalidLenrust-analyzer cargo udevrs 0.4.0 error/Error#InvalidLen#(values_count as usize)) |
| 111 | } else { |
| 112 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/impl#[TrieNode][`TryFrom<&[u8]>`] { |
| 113 | prefix_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#prefix_off., |
| 114 | children_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#children_count., |
| 115 | _paddingrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#_padding., |
| 116 | values_countrust-analyzer cargo udevrs 0.4.0 hwdb/trie/node/TrieNode#values_count., |
| 117 | }) |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | } |