| 1 |
|
| 2 |
|
| 3 |
use super::Tag; |
| 4 |
use core::fmt; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] |
| 20 |
pub struct TagNumber(pub u32); |
| 21 |
|
| 22 |
impl TagNumber { |
| 23 |
|
| 24 |
pub(super) const MASK: u8 = 0b11111; |
| 25 |
|
| 26 |
|
| 27 |
#[deprecated( |
| 28 |
since = "0.8.0", |
| 29 |
note = "use TagNumber(value) directly as inner field is now pub" |
| 30 |
)] |
| 31 |
#[must_use] |
| 32 |
pub const fn new(value: u32) -> Self { |
| 33 |
Self(value) |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
#[must_use] |
| 38 |
pub fn application(self, constructed: bool) -> Tag { |
| 39 |
Tag::Application { |
| 40 |
constructed, |
| 41 |
number: self, |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
#[must_use] |
| 47 |
pub fn context_specific(self, constructed: bool) -> Tag { |
| 48 |
Tag::ContextSpecific { |
| 49 |
constructed, |
| 50 |
number: self, |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
#[must_use] |
| 56 |
pub fn private(self, constructed: bool) -> Tag { |
| 57 |
Tag::Private { |
| 58 |
constructed, |
| 59 |
number: self, |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
#[must_use] |
| 65 |
pub fn value(self) -> u32 { |
| 66 |
self.0 |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
impl From<u32> for TagNumber { |
| 71 |
fn from(value: u32) -> TagNumber { |
| 72 |
TagNumber(value) |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
impl From<TagNumber> for u32 { |
| 77 |
fn from(number: TagNumber) -> u32 { |
| 78 |
number.0 |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
impl fmt::Display for TagNumber { |
| 83 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 84 |
write!(f, "{}", self.0) |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
#[cfg(feature = "arbitrary")] |
| 91 |
impl<'a> arbitrary::Arbitrary<'a> for TagNumber { |
| 92 |
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> { |
| 93 |
Ok(Self(u.int_in_range(0..=30)?)) |
| 94 |
} |
| 95 |
|
| 96 |
fn size_hint(depth: usize) -> (usize, Option<usize>) { |
| 97 |
u8::size_hint(depth) |
| 98 |
} |
| 99 |
} |