1crate::create! {
2 #[repr(u8)]
3 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
5 #[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
6 pub enum Ton {
7 #[default]
8 Unknown = 0b00000000,
9 International = 0b00000001,
10 National = 0b00000010,
11 NetworkSpecific = 0b00000011,
12 SubscriberNumber = 0b00000100,
13 Alphanumeric = 0b00000101,
14 Abbreviated = 0b00000110,
15 Other(u8),
16 }
17}
18
19impl Ton {
20 pub fn null() -> Self {
24 Self::default()
25 }
26}
27
28impl From<u8> for Ton {
29 fn from(value: u8) -> Self {
30 match value {
31 0b00000000 => Ton::Unknown,
32 0b00000001 => Ton::International,
33 0b00000010 => Ton::National,
34 0b00000011 => Ton::NetworkSpecific,
35 0b00000100 => Ton::SubscriberNumber,
36 0b00000101 => Ton::Alphanumeric,
37 0b00000110 => Ton::Abbreviated,
38 value => Ton::Other(value),
39 }
40 }
41}
42
43impl From<Ton> for u8 {
44 fn from(value: Ton) -> Self {
45 match value {
46 Ton::Unknown => 0b00000000,
47 Ton::International => 0b00000001,
48 Ton::National => 0b00000010,
49 Ton::NetworkSpecific => 0b00000011,
50 Ton::SubscriberNumber => 0b00000100,
51 Ton::Alphanumeric => 0b00000101,
52 Ton::Abbreviated => 0b00000110,
53 Ton::Other(value) => value,
54 }
55 }
56}
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn encode_decode() {
64 crate::tests::encode_decode_test_instances::<Ton>();
65 }
66}