| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/; |
| 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 child entry in the hardware database. |
| 6 | /// |
| 7 | /// Array of child entries that directly follows the node record. |
| 8 | #[repr(C, packed(8))] |
| 9 | #[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:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 10 | pub struct TrieChildEntryrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry# { |
| 11 | crust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#c.: u8, |
| 12 | _paddingrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#_padding.: [u8; 7], |
| 13 | child_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#child_off.: u64, |
| 14 | } |
| 15 | |
| 16 | impl TrieChildEntryrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry# { |
| 17 | /// Creates a new [TrieChildEntry]. |
| 18 | pub const fn newrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry]new().() -> Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry] { |
| 19 | Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry] { |
| 20 | crust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#c.: 0, |
| 21 | _paddingrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#_padding.: [0u8; 7], |
| 22 | child_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#child_off.: 0, |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | /// Gets the length of the encoded [TrieChildEntry]. |
| 27 | pub fn lenrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry]len().(&self) -> usize { |
| 28 | hwdbrust-analyzer cargo udevrs 0.4.0 hwdb/::child_entry_sizerust-analyzer cargo udevrs 0.4.0 hwdb/child_entry_size().() |
| 29 | } |
| 30 | |
| 31 | /// Gets whether the [TrieChildEntry] is empty. |
| 32 | pub const fn is_emptyrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry]is_empty().(&self) -> bool { |
| 33 | false |
| 34 | } |
| 35 | |
| 36 | /// Gets the index of the child node. |
| 37 | pub const fn crust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry]c().(&self) -> u8 { |
| 38 | self.crust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#c. |
| 39 | } |
| 40 | |
| 41 | /// Sets the index of the child node. |
| 42 | pub fn set_crust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry]set_c().(&mut self, val: u8) { |
| 43 | self.crust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#c. = val; |
| 44 | } |
| 45 | |
| 46 | /// Builder function that sets the index of the child node. |
| 47 | pub fn with_crust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry]with_c().(mut self, val: u8) -> Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry] { |
| 48 | self.set_crust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry]set_c().(val); |
| 49 | self |
| 50 | } |
| 51 | |
| 52 | /// Gets the offset of the child node. |
| 53 | pub const fn child_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry]child_off().(&self) -> u64 { |
| 54 | self.child_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#child_off. |
| 55 | } |
| 56 | |
| 57 | /// Sets the offset of the child node. |
| 58 | pub fn set_child_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry]set_child_off().(&mut self, val: u64) { |
| 59 | self.child_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#child_off. = val; |
| 60 | } |
| 61 | |
| 62 | /// Builder function that sets the offset of the child node. |
| 63 | pub fn with_child_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry]with_child_off().(mut self, val: u64) -> Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry] { |
| 64 | self.set_child_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry]set_child_off().(val); |
| 65 | self |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&[u8]> for TrieChildEntryrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry# { |
| 70 | type Errorrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry][`TryFrom<&[u8]>`]Error# = Errorrust-analyzer cargo udevrs 0.4.0 error/Error#; |
| 71 | |
| 72 | fn try_fromrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry][`TryFrom<&[u8]>`]try_from().(val: &[u8]) -> Resultrust-analyzer cargo udevrs 0.4.0 error/Result#<Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry][`TryFrom<&[u8]>`]> { |
| 73 | 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().hwdbrust-analyzer cargo udevrs 0.4.0 hwdb/::child_entry_sizerust-analyzer cargo udevrs 0.4.0 hwdb/child_entry_size().() { |
| 74 | 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().())) |
| 75 | } else { |
| 76 | // TODO: parse use get ranges and offsets |
| 77 | let mut idx = 0usize; |
| 78 | |
| 79 | let c = 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().; |
| 80 | let _padding = [0u8; 7]; |
| 81 | |
| 82 | // skip `c` index + padding |
| 83 | 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; |
| 84 | |
| 85 | let child_off = |
| 86 | 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().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/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<u64>()]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().); |
| 87 | |
| 88 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry][`TryFrom<&[u8]>`] { |
| 89 | crust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#c., |
| 90 | _paddingrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#_padding., |
| 91 | child_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#child_off., |
| 92 | }) |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | impl Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# for TrieChildEntryrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry# { |
| 98 | fn cmprust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry][Ord]cmp().(&self, other: &Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry][Ord]) -> cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# { |
| 99 | self.crust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#c..cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][Ord]cmp().(&other.crust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#c.) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | impl PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd# for TrieChildEntryrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry# { |
| 104 | fn partial_cmprust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry][`PartialOrd<Self>`]partial_cmp().(&self, other: &Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/impl#[TrieChildEntry][`PartialOrd<Self>`]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> { |
| 105 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.crust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#c..cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][Ord]cmp().(&other.crust-analyzer cargo udevrs 0.4.0 hwdb/trie/child_entry/TrieChildEntry#c.)) |
| 106 | } |
| 107 | } |