Debian Codegraph @

src/unit.rs

raw symbols SCIP
1 /// UnitID is an alias of `usize`.
2 pub type UnitIDrust-analyzer cargo yada 0.5.1 unit/UnitID# = usize;
3
4 /// The size of `Unit` (4).
5 pub const UNIT_SIZErust-analyzer cargo yada 0.5.1 unit/UNIT_SIZE.: usize = 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().::<u32>();
6
7 /// An unit represents an element in a double-array.
8 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
9 pub struct Unitrust-analyzer cargo yada 0.5.1 unit/Unit#(u32);
10
11 /// Unit represents one node of a double array trie. The bit width of each node is 32-bits.
12 ///
13 /// The bit layout of a non-leaf node:
14 ///
15 /// 0 1 2 3
16 /// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
17 /// +---------------+-+-+-----------------------------------------+-+
18 /// | LABEL |H|E| OFFSET |I|
19 /// +---------------+-+-+-----------------------------------------+-+
20 ///
21 /// LABEL 8-bits value that represents a label of the double array node.
22 /// HAS_LEAF (H) 1-bit flag that indicates whether the node has leaf nodes or not.
23 /// EXTEND_OFFSET (E) 1-bit flag that indicates whether the offset should be extended or not.
24 /// OFFSET 21-bits value that represents an offset of the double array node.
25 /// IS_LEAF (I) 1-bit flag that indicates whether the node is a leaf node or not.
26 /// This flag is always 0 in this case.
27 ///
28 /// The bit layout of a leaf node:
29 ///
30 /// 0 1 2 3
31 /// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
32 /// +-------------------------------------------------------------+-+
33 /// | VALUE |I|
34 /// +-------------------------------------------------------------+-+
35 ///
36 /// VALUE 31-bits value that represents a value of the double array node.
37 /// IS_LEAF (I) 1-bit flag that indicates whether the node is a leaf node or not.
38 /// This flag is always 1 in this case.
39 impl Unitrust-analyzer cargo yada 0.5.1 unit/Unit# {
40 /// Creates a new Unit.
41 #[inline]
42 pub const fn newrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]new().() -> Selfrust-analyzer cargo yada 0.5.1 unit/impl#[Unit] {
43 Selfrust-analyzer cargo yada 0.5.1 unit/impl#[Unit](0)
44 }
45
46 /// Creates a new Unit from `value`.
47 #[inline]
48 pub fn from_u32rust-analyzer cargo yada 0.5.1 unit/impl#[Unit]from_u32().(value: u32) -> Selfrust-analyzer cargo yada 0.5.1 unit/impl#[Unit] {
49 Selfrust-analyzer cargo yada 0.5.1 unit/impl#[Unit](value)
50 }
51
52 /// Returns an internal 32 bit integer.
53 #[inline]
54 pub fn as_u32rust-analyzer cargo yada 0.5.1 unit/impl#[Unit]as_u32().(&self) -> u32 {
55 self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0.
56 }
57
58 /// Returns true if the unit have a leaf as a child unit. Otherwise, returns false.
59 #[inline]
60 pub fn has_leafrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]has_leaf().(&self) -> bool {
61 self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().1
62 }
63
64 /// Returns true if the unit is a leaf which have a value. Otherwise, return false.
65 #[inline]
66 pub fn is_leafrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]is_leaf().(&self) -> bool {
67 self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().31 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().1
68 }
69
70 /// Returns a 31 bits unsigned integer value associated with the unit.
71 #[inline]
72 pub fn valuerust-analyzer cargo yada 0.5.1 unit/impl#[Unit]value().(&self) -> u32 {
73 self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().0x7FFFFFFF
74 }
75
76 /// Returns a label (<= 255) if the unit is not a leaf. Otherwise, returns an integer value greater
77 /// than 255.
78 #[inline]
79 pub fn labelrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]label().(&self) -> u32 {
80 self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().((1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().31) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().0xFF)
81 }
82
83 /// Returns an offset value within the unit. If the offset extension flag is true, returns the
84 /// offset multiplied by 256.
85 #[inline]
86 pub fn offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]offset().(&self) -> u32 {
87 (self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().10) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<Self>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<Self>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<Self>`]shl().((self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().9)) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().6)
88 }
89
90 /// Sets an offset to the unit. `offset` should be a value less than or equal to 29 bits. If the
91 /// `offset` is greater than 21 bits, sets the offset extension flag and the `offset` without
92 /// lower 8 bits (then, lower 8 bits of the given `offset` should be 0).
93 #[inline]
94 pub fn set_offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_offset().(&mut self, offset: u32) {
95 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(offset <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt(). (1u32 << 29));
96
97 if offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().(1u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().21) {
98 // don't extend offset
99 self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. = offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().10 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().(self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<Self>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<Self>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<Self>`]shl().23 as u32) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().23;
100 } else {
101 // extend offset
102 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((offset << 2) &rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). (1 << 31), 0, "MSB of offset should be 0");
103 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(offset &rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). 0xFF, 0, "lower 8 bits of offset should be 0");
104 self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. = offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().9) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().(self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<Self>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<Self>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<Self>`]shl().23 as u32) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().23; // with offset extension flag
105 }
106 }
107
108 /// Sets a `has_leaf` flag to the unit.
109 #[inline]
110 pub fn set_has_leafrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_has_leaf().(&mut self, has_leaf: bool) {
111 self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. = if has_leaf {
112 self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().8
113 } else {
114 self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][Not]not().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().8)
115 }
116 }
117
118 /// Sets a label to the unit.
119 #[inline]
120 pub fn set_labelrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_label().(&mut self, label: u8) {
121 self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. = (self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().8) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().(label as u32)
122 }
123
124 /// Sets a value to the unit.
125 #[inline]
126 pub fn set_valuerust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_value().(&mut self, value: u32) {
127 self.0rust-analyzer cargo yada 0.5.1 unit/Unit#0. = value rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().31
128 }
129
130 /// Returns a string representation of the unit.
131 pub fn to_stringrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]to_string().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
132 if self.is_leafrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]is_leaf().() {
133 // leaf node
134 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Unit {{ value: {} }}", self.valuerust-analyzer cargo yada 0.5.1 unit/impl#[Unit]value().()).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
135 } else {
136 // internal node
137 let label = self.labelrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]label().();
138 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
139 "Unit {{ offset: {}, label: {}, has_leaf: {} }}",
140 self.offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]offset().(),
141 match label {
142 0 => "NULL".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
143 1..=255 => ((label as u8) as char).escape_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]escape_default().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
144 _ => "INVALID".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
145 },
146 self.has_leafrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]has_leaf().()
147 )
148 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
149 }
150 }
151 }
152
153 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Unitrust-analyzer cargo yada 0.5.1 unit/Unit# {
154 fn fmtrust-analyzer cargo yada 0.5.1 unit/impl#[Unit][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
155 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", self.to_stringrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]to_string().())
156 }
157 }
158
159 #[cfg(test)]
160 mod testsrust-analyzer cargo yada 0.5.1 unit/tests/ {
161 use craterust-analyzer cargo yada 0.5.1 crate/::Unitrust-analyzer cargo yada 0.5.1 unit/Unit#;
162
163 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
164 fn test_unit_valuerust-analyzer cargo yada 0.5.1 unit/tests/test_unit_value().() {
165 let mut unit = Unitrust-analyzer cargo yada 0.5.1 unit/Unit#::newrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]new().();
166 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unit.valuerust-analyzer cargo yada 0.5.1 unit/impl#[Unit]value().(), 0);
167
168 unit.set_valuerust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_value().(5);
169 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unit.valuerust-analyzer cargo yada 0.5.1 unit/impl#[Unit]value().(), 5);
170
171 unit.set_valuerust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_value().((1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().31) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().1);
172 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unit.valuerust-analyzer cargo yada 0.5.1 unit/impl#[Unit]value().(), (1 << 31) -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). 1);
173
174 unit.set_valuerust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_value().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().31);
175 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unit.valuerust-analyzer cargo yada 0.5.1 unit/impl#[Unit]value().(), 0);
176 }
177
178 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
179 fn test_labelrust-analyzer cargo yada 0.5.1 unit/tests/test_label().() {
180 let unit = Unitrust-analyzer cargo yada 0.5.1 unit/Unit#::newrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]new().();
181 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unit.labelrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]label().(), 0);
182
183 let mut unit = Unitrust-analyzer cargo yada 0.5.1 unit/Unit#::newrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]new().();
184 unit.set_labelrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_label().(0);
185 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unit.labelrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]label().(), 0);
186
187 let mut unit = Unitrust-analyzer cargo yada 0.5.1 unit/Unit#::newrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]new().();
188 unit.set_labelrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_label().(1);
189 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unit.labelrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]label().(), 1);
190
191 let mut unit = Unitrust-analyzer cargo yada 0.5.1 unit/Unit#::newrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]new().();
192 unit.set_labelrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_label().(255);
193 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unit.labelrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]label().(), 255);
194 }
195
196 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
197 fn test_offsetrust-analyzer cargo yada 0.5.1 unit/tests/test_offset().() {
198 let unit = Unitrust-analyzer cargo yada 0.5.1 unit/Unit#::newrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]new().();
199 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unit.offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]offset().(), 0);
200
201 let mut unit = Unitrust-analyzer cargo yada 0.5.1 unit/Unit#::newrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]new().();
202 unit.set_offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_offset().(0);
203 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unit.offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]offset().(), 0);
204
205 let mut unit = Unitrust-analyzer cargo yada 0.5.1 unit/Unit#::newrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]new().();
206 unit.set_offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_offset().(1);
207 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unit.offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]offset().(), 1);
208
209 let mut unit = Unitrust-analyzer cargo yada 0.5.1 unit/Unit#::newrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]new().();
210 unit.set_offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_offset().((1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().21) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().1);
211 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unit.offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]offset().(), (1 << 21) -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). 1);
212
213 let mut unit = Unitrust-analyzer cargo yada 0.5.1 unit/Unit#::newrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]new().();
214 unit.set_offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_offset().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().21);
215 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unit.offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]offset().(), 1 << 21);
216
217 let mut unit = Unitrust-analyzer cargo yada 0.5.1 unit/Unit#::newrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]new().();
218 unit.set_offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]set_offset().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().28);
219 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(unit.offsetrust-analyzer cargo yada 0.5.1 unit/impl#[Unit]offset().(), 1 << 28);
220 }
221 }