Debian Codegraph @

src/hwdb/trie/value_entry.rs

raw symbols SCIP
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 value entry in the hardware database.
6 ///
7 /// Array of value 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:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
10 pub struct TrieValueEntryrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/TrieValueEntry# {
11 key_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/TrieValueEntry#key_off.: u64,
12 value_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/TrieValueEntry#value_off.: u64,
13 }
14
15 impl TrieValueEntryrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/TrieValueEntry# {
16 /// Creates a new [TrieValueEntry].
17 pub const fn newrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry]new().() -> Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry] {
18 Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry] {
19 key_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/TrieValueEntry#key_off.: 0,
20 value_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/TrieValueEntry#value_off.: 0,
21 }
22 }
23
24 /// Gets the length of the encoded [TrieValueEntry].
25 pub fn lenrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry]len().(&self) -> usize {
26 hwdbrust-analyzer cargo udevrs 0.4.0 hwdb/::value_entry_sizerust-analyzer cargo udevrs 0.4.0 hwdb/value_entry_size().()
27 }
28
29 /// Gets whether the [TrieValueEntry] is empty.
30 pub const fn is_emptyrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry]is_empty().(&self) -> bool {
31 false
32 }
33
34 /// Gets key offset.
35 pub const fn key_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry]key_off().(&self) -> u64 {
36 self.key_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/TrieValueEntry#key_off.
37 }
38
39 /// Sets key offset.
40 pub fn set_key_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry]set_key_off().(&mut self, val: u64) {
41 self.key_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/TrieValueEntry#key_off. = val;
42 }
43
44 /// Builder function that sets the key offset.
45 pub fn with_key_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry]with_key_off().(mut self, val: u64) -> Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry] {
46 self.set_key_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry]set_key_off().(val);
47 self
48 }
49
50 /// Gets value offset.
51 pub const fn value_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry]value_off().(&self) -> u64 {
52 self.value_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/TrieValueEntry#value_off.
53 }
54
55 /// Sets value offset.
56 pub fn set_value_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry]set_value_off().(&mut self, val: u64) {
57 self.value_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/TrieValueEntry#value_off. = val;
58 }
59
60 /// Builder function that sets the value offset.
61 pub fn with_value_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry]with_value_off().(mut self, val: u64) -> Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry] {
62 self.set_value_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry]set_value_off().(val);
63 self
64 }
65 }
66
67 impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&[u8]> for TrieValueEntryrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/TrieValueEntry# {
68 type Errorrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry][`TryFrom<&[u8]>`]Error# = Errorrust-analyzer cargo udevrs 0.4.0 error/Error#;
69
70 fn try_fromrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry][`TryFrom<&[u8]>`]try_from().(val: &[u8]) -> Resultrust-analyzer cargo udevrs 0.4.0 error/Result#<Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry][`TryFrom<&[u8]>`]> {
71 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/::value_entry_sizerust-analyzer cargo udevrs 0.4.0 hwdb/value_entry_size().() {
72 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().()))
73 } else {
74 // TODO: parse use get ranges and offsets
75 let mut idx = 0usize;
76 let mut idx_end = 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>();
77
78 let key_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_end]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().);
79 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().idx_end;
80 idx_end 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().idx_end;
81
82 let value_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_end]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().);
83
84 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/impl#[TrieValueEntry][`TryFrom<&[u8]>`] { key_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/TrieValueEntry#key_off., value_offrust-analyzer cargo udevrs 0.4.0 hwdb/trie/value_entry/TrieValueEntry#value_off. })
85 }
86 }
87 }