| 1 | //! Arcs are integer values which exist within an OID's hierarchy. |
| 2 | |
| 3 | use craterust-analyzer cargo const-oid 0.10.2 crate/::{Errorrust-analyzer cargo const-oid 0.10.2 error/Error#, Resultrust-analyzer cargo const-oid 0.10.2 error/Result#}; |
| 4 | |
| 5 | #[cfg(doc)] |
| 6 | use craterust-analyzer cargo const-oid 0.10.2 crate/::ObjectIdentifierrust-analyzer cargo const-oid 0.10.2 ObjectIdentifier#; |
| 7 | |
| 8 | /// Type alias used to represent an "arc", i.e. integer identifier value, where an OID comprises a |
| 9 | /// sequence of arcs. |
| 10 | /// |
| 11 | /// X.660 does not define a maximum size of an arc. We instead follow Mozilla* conventions for |
| 12 | /// maximum values of an arc, with a maximum value of 2^32-1 (4294967295), a.k.a. [`u32::MAX`] |
| 13 | /// with [`Arc`] being a type alias for [`u32`]. |
| 14 | /// |
| 15 | /// Note that this means we deliberately do *NOT* support UUIDs used as OIDs. |
| 16 | /// |
| 17 | /// *NOTE: please see this study for a survey of how various OID libraries handle maximum arcs: |
| 18 | /// <https://misc.daniel-marschall.de/asn.1/oid_facts.html> |
| 19 | pub type Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc# = u32; |
| 20 | |
| 21 | /// Maximum value of the first arc in an OID. |
| 22 | pub(craterust-analyzer cargo const-oid 0.10.2 crate/) const ARC_MAX_FIRSTrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_FIRST.: Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc# = 2; |
| 23 | |
| 24 | /// Maximum value of the second arc in an OID. |
| 25 | pub(craterust-analyzer cargo const-oid 0.10.2 crate/) const ARC_MAX_SECONDrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_SECOND.: Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc# = 39; |
| 26 | |
| 27 | /// Maximum number of bytes supported in an arc. |
| 28 | /// |
| 29 | /// Note that OIDs are base 128 encoded (with continuation bits), so we must consider how many bytes |
| 30 | /// are required when each byte can only represent 7-bits of the input. |
| 31 | const ARC_MAX_BYTESrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_BYTES.: usize = (Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc#::BITSrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]BITS. as usize).div_ceilrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]div_ceil().(7); |
| 32 | |
| 33 | /// Maximum value of the last byte in an arc. |
| 34 | const ARC_MAX_LAST_OCTETrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_LAST_OCTET.: u8 = 0b11110000; // Max bytes of leading 1-bits |
| 35 | |
| 36 | /// [`Iterator`] over [`Arc`] values (a.k.a. nodes) in an [`ObjectIdentifier`]. |
| 37 | /// |
| 38 | /// This iterates over all arcs in an OID, including the root. |
| 39 | pub struct Arcsrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#<'a> { |
| 40 | /// OID bytes we're iterating over. |
| 41 | bytesrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#bytes.: &'a [u8], |
| 42 | |
| 43 | /// Current position within the serialized BER bytes of this OID. |
| 44 | cursorrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#cursor.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>, |
| 45 | } |
| 46 | |
| 47 | impl<'a> Arcsrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#<'a> { |
| 48 | /// Create a new iterator over an OID encoded as BER bytes. |
| 49 | pub(craterust-analyzer cargo const-oid 0.10.2 crate/) fn newrust-analyzer cargo const-oid 0.10.2 arcs/impl#[`Arcs<'a>`]new().(bytes: &'a [u8]) -> Selfrust-analyzer cargo const-oid 0.10.2 arcs/impl#[`Arcs<'a>`] { |
| 50 | Selfrust-analyzer cargo const-oid 0.10.2 arcs/impl#[`Arcs<'a>`] { |
| 51 | bytesrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#bytes., |
| 52 | cursorrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#cursor.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /// Try to parse the next arc in this OID. |
| 57 | /// |
| 58 | /// This method is fallible so it can be used as a first pass to determine |
| 59 | /// that the arcs in the OID are well-formed. |
| 60 | pub(craterust-analyzer cargo const-oid 0.10.2 crate/) fn try_nextrust-analyzer cargo const-oid 0.10.2 arcs/impl#[`Arcs<'a>`]try_next().(&mut self) -> Resultrust-analyzer cargo const-oid 0.10.2 error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc#>> { |
| 61 | match self.cursorrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#cursor. { |
| 62 | // Indicates we're on the root arc |
| 63 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 64 | let root_byte = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self.bytesrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#bytes..firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().().ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::Emptyrust-analyzer cargo const-oid 0.10.2 error/Error#Empty#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 65 | let root = RootArcsrust-analyzer cargo const-oid 0.10.2 arcs/RootArcs#::try_fromrust-analyzer cargo const-oid 0.10.2 arcs/impl#[RootArcs][`TryFrom<u8>`]try_from().(root_byte)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 66 | self.cursorrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#cursor. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0); |
| 67 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(root.first_arcrust-analyzer cargo const-oid 0.10.2 arcs/impl#[RootArcs]first_arc().())) |
| 68 | } |
| 69 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0) => { |
| 70 | let root = RootArcsrust-analyzer cargo const-oid 0.10.2 arcs/RootArcs#::try_fromrust-analyzer cargo const-oid 0.10.2 arcs/impl#[RootArcs][`TryFrom<u8>`]try_from().(self.bytesrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#bytes.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 71 | self.cursorrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#cursor. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1); |
| 72 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(root.second_arcrust-analyzer cargo const-oid 0.10.2 arcs/impl#[RootArcs]second_arc().())) |
| 73 | } |
| 74 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(offset) => { |
| 75 | let mut result = 0; |
| 76 | let mut arc_bytes = 0; |
| 77 | |
| 78 | loop { |
| 79 | let len = checked_addrust-analyzer cargo const-oid 0.10.2 checked/checked_add!!(offset, arc_bytes); |
| 80 | |
| 81 | match self.bytesrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#bytes..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(len).clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().() { |
| 82 | // The arithmetic below includes advance checks |
| 83 | // against `ARC_MAX_BYTES` and `ARC_MAX_LAST_OCTET` |
| 84 | // which ensure the operations will not overflow. |
| 85 | #[allow(clippy::arithmetic_side_effects)] |
| 86 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(byte) => { |
| 87 | arc_bytes = checked_addrust-analyzer cargo const-oid 0.10.2 checked/checked_add!!(arc_bytes, 1); |
| 88 | |
| 89 | if (arc_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().ARC_MAX_BYTESrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_BYTES.) && (byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().ARC_MAX_LAST_OCTETrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_LAST_OCTET. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0) { |
| 90 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::ArcTooBigrust-analyzer cargo const-oid 0.10.2 error/Error#ArcTooBig#); |
| 91 | } |
| 92 | |
| 93 | result = (result 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().7) 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().(byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().0b1111111) as Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc#; |
| 94 | |
| 95 | if byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().0b10000000 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 { |
| 96 | self.cursorrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#cursor. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(checked_addrust-analyzer cargo const-oid 0.10.2 checked/checked_add!!(offset, arc_bytes)); |
| 97 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(result)); |
| 98 | } |
| 99 | } |
| 100 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 101 | if arc_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 102 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 103 | } else { |
| 104 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::Base128rust-analyzer cargo const-oid 0.10.2 error/Error#Base128#); |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Arcsrust-analyzer cargo const-oid 0.10.2 arcs/Arcs#<'_> { |
| 115 | type Itemrust-analyzer cargo const-oid 0.10.2 arcs/impl#[`Arcs<'_>`][Iterator]Item# = Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc#; |
| 116 | |
| 117 | fn nextrust-analyzer cargo const-oid 0.10.2 arcs/impl#[`Arcs<'_>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc#> { |
| 118 | // ObjectIdentifier constructors should ensure the OID is well-formed |
| 119 | self.try_nextrust-analyzer cargo const-oid 0.10.2 arcs/impl#[`Arcs<'a>`]try_next().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("OID malformed") |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /// Byte containing the first and second arcs of an OID. |
| 124 | /// |
| 125 | /// This is represented this way in order to reduce the overall size of the |
| 126 | /// [`ObjectIdentifier`] struct. |
| 127 | #[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:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, 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:)] |
| 128 | struct RootArcsrust-analyzer cargo const-oid 0.10.2 arcs/RootArcs#(u8); |
| 129 | |
| 130 | impl RootArcsrust-analyzer cargo const-oid 0.10.2 arcs/RootArcs# { |
| 131 | /// Create [`RootArcs`] from the first and second arc values represented |
| 132 | /// as `Arc` integers. |
| 133 | pub(craterust-analyzer cargo const-oid 0.10.2 crate/) const fn newrust-analyzer cargo const-oid 0.10.2 arcs/impl#[RootArcs]new().(first_arc: Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc#, second_arc: Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc#) -> Resultrust-analyzer cargo const-oid 0.10.2 error/Result#<Selfrust-analyzer cargo const-oid 0.10.2 arcs/impl#[RootArcs]> { |
| 134 | if first_arc rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().ARC_MAX_FIRSTrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_FIRST. { |
| 135 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::ArcInvalidrust-analyzer cargo const-oid 0.10.2 error/Error#ArcInvalid# { arcrust-analyzer cargo const-oid 0.10.2 error/Error#ArcInvalid#arc.: first_arc }); |
| 136 | } |
| 137 | |
| 138 | if second_arc rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().ARC_MAX_SECONDrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_SECOND. { |
| 139 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo const-oid 0.10.2 error/Error#::ArcInvalidrust-analyzer cargo const-oid 0.10.2 error/Error#ArcInvalid# { arcrust-analyzer cargo const-oid 0.10.2 error/Error#ArcInvalid#arc.: second_arc }); |
| 140 | } |
| 141 | |
| 142 | // The checks above ensure this operation will not overflow |
| 143 | #[allow(clippy::arithmetic_side_effects)] |
| 144 | let byte = (first_arc rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().(ARC_MAX_SECONDrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_SECOND. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().1)) as u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add().second_arc as u8; |
| 145 | |
| 146 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo const-oid 0.10.2 arcs/impl#[RootArcs](byte)) |
| 147 | } |
| 148 | |
| 149 | /// Get the value of the first arc |
| 150 | #[allow(clippy::arithmetic_side_effects)] |
| 151 | pub(craterust-analyzer cargo const-oid 0.10.2 crate/) const fn first_arcrust-analyzer cargo const-oid 0.10.2 arcs/impl#[RootArcs]first_arc().(self) -> Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc# { |
| 152 | self.0rust-analyzer cargo const-oid 0.10.2 arcs/RootArcs#0. as Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc# rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().(ARC_MAX_SECONDrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_SECOND. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().1) |
| 153 | } |
| 154 | |
| 155 | /// Get the value of the second arc |
| 156 | #[allow(clippy::arithmetic_side_effects)] |
| 157 | pub(craterust-analyzer cargo const-oid 0.10.2 crate/) const fn second_arcrust-analyzer cargo const-oid 0.10.2 arcs/impl#[RootArcs]second_arc().(self) -> Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc# { |
| 158 | self.0rust-analyzer cargo const-oid 0.10.2 arcs/RootArcs#0. as Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc# rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().(ARC_MAX_SECONDrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_SECOND. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().1) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<u8> for RootArcsrust-analyzer cargo const-oid 0.10.2 arcs/RootArcs# { |
| 163 | type Errorrust-analyzer cargo const-oid 0.10.2 arcs/impl#[RootArcs][`TryFrom<u8>`]Error# = Errorrust-analyzer cargo const-oid 0.10.2 error/Error#; |
| 164 | |
| 165 | // Ensured not to overflow by constructor invariants |
| 166 | #[allow(clippy::arithmetic_side_effects)] |
| 167 | fn try_fromrust-analyzer cargo const-oid 0.10.2 arcs/impl#[RootArcs][`TryFrom<u8>`]try_from().(octet: u8) -> Resultrust-analyzer cargo const-oid 0.10.2 error/Result#<Selfrust-analyzer cargo const-oid 0.10.2 arcs/impl#[RootArcs][`TryFrom<u8>`]> { |
| 168 | let first = octet as Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc# rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().(ARC_MAX_SECONDrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_SECOND. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().1); |
| 169 | let second = octet as Arcrust-analyzer cargo const-oid 0.10.2 arcs/Arc# rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().(ARC_MAX_SECONDrust-analyzer cargo const-oid 0.10.2 arcs/ARC_MAX_SECOND. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().1); |
| 170 | let result = Selfrust-analyzer cargo const-oid 0.10.2 arcs/impl#[RootArcs][`TryFrom<u8>`]::newrust-analyzer cargo const-oid 0.10.2 arcs/impl#[RootArcs]new().(first, second)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 171 | debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(octet, result.0rust-analyzer cargo const-oid 0.10.2 arcs/RootArcs#0.); |
| 172 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(result) |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<RootArcsrust-analyzer cargo const-oid 0.10.2 arcs/RootArcs#> for u8 { |
| 177 | fn fromrust-analyzer cargo const-oid 0.10.2 arcs/impl#[u8][`From<RootArcs>`]from().(root_arcs: RootArcsrust-analyzer cargo const-oid 0.10.2 arcs/RootArcs#) -> u8 { |
| 178 | root_arcs.0rust-analyzer cargo const-oid 0.10.2 arcs/RootArcs#0. |
| 179 | } |
| 180 | } |