hex_wrapper/nonzero.rs
1impl_nonzero_hex! {
2 /// Pointer-sized unsigned nonzero hexadecimal numbers.
3 ///
4 /// ```rust
5 /// use hex_wrapper::NonZeroHexUsize;
6 ///
7 /// // from random value
8 /// let rand = NonZeroHexUsize::rand();
9 /// let inner = rand.get();
10 /// assert_eq!(rand.to_string(), format!("{:x}", inner));
11 ///
12 /// // from given value
13 /// let given = NonZeroHexUsize::new(0xa3).unwrap();
14 /// assert_eq!(given.to_string(), String::from("a3"));
15 ///
16 /// // from string
17 /// let from_str = "a3".parse::<NonZeroHexUsize>();
18 /// assert_eq!(from_str.unwrap(), NonZeroHexUsize::new(0xa3).unwrap());
19 /// ```
20 pub struct NonZeroHexUsize(usize);
21}
22
23impl_nonzero_hex! {
24 /// 128-bit unsigned nonzero hexadecimal numbers.
25 ///
26 /// ```rust
27 /// use hex_wrapper::NonZeroHex128;
28 ///
29 /// // from random value
30 /// let rand = NonZeroHex128::rand();
31 /// let inner = rand.get();
32 /// assert_eq!(rand.to_string(), format!("{:x}", inner));
33 ///
34 /// // from given value
35 /// let given = NonZeroHex128::new(0xa3).unwrap();
36 /// assert_eq!(given.to_string(), String::from("a3"));
37 ///
38 /// // from string
39 /// let from_str = "a3".parse::<NonZeroHex128>();
40 /// assert_eq!(from_str.unwrap(), NonZeroHex128::new(0xa3).unwrap());
41 /// ```
42 pub struct NonZeroHex128(u128);
43}
44
45impl_nonzero_hex! {
46 /// 64-bit unsigned nonzero hexadecimal numbers.
47 ///
48 /// ```rust
49 /// use hex_wrapper::NonZeroHex64;
50 ///
51 /// // from random value
52 /// let rand = NonZeroHex64::rand();
53 /// let inner = rand.get();
54 /// assert_eq!(rand.to_string(), format!("{:x}", inner));
55 ///
56 /// // from given value
57 /// let given = NonZeroHex64::new(0xa3).unwrap();
58 /// assert_eq!(given.to_string(), String::from("a3"));
59 ///
60 /// // from string
61 /// let from_str = "a3".parse::<NonZeroHex64>();
62 /// assert_eq!(from_str.unwrap(), NonZeroHex64::new(0xa3).unwrap());
63 /// ```
64 pub struct NonZeroHex64(u64);
65}
66
67impl_nonzero_hex! {
68 /// 32-bit unsigned nonzero hexadecimal numbers.
69 ///
70 /// ```rust
71 /// use hex_wrapper::NonZeroHex32;
72 ///
73 /// // from random value
74 /// let rand = NonZeroHex32::rand();
75 /// let inner = rand.get();
76 /// assert_eq!(rand.to_string(), format!("{:x}", inner));
77 ///
78 /// // from given value
79 /// let given = NonZeroHex32::new(0xa3).unwrap();
80 /// assert_eq!(given.to_string(), String::from("a3"));
81 ///
82 /// // from string
83 /// let from_str = "a3".parse::<NonZeroHex32>();
84 /// assert_eq!(from_str.unwrap(), NonZeroHex32::new(0xa3).unwrap());
85 /// ```
86 pub struct NonZeroHex32(u32);
87}
88
89impl_nonzero_hex! {
90 /// 16-bit unsigned nonzero hexadecimal numbers.
91 ///
92 /// ```rust
93 /// use hex_wrapper::NonZeroHex16;
94 ///
95 /// // from random value
96 /// let rand = NonZeroHex16::rand();
97 /// let inner = rand.get();
98 /// assert_eq!(rand.to_string(), format!("{:x}", inner));
99 ///
100 /// // from given value
101 /// let given = NonZeroHex16::new(0xa3).unwrap();
102 /// assert_eq!(given.to_string(), String::from("a3"));
103 ///
104 /// // from string
105 /// let from_str = "a3".parse::<NonZeroHex16>();
106 /// assert_eq!(from_str.unwrap(), NonZeroHex16::new(0xa3).unwrap());
107 /// ```
108 pub struct NonZeroHex16(u16);
109}
110
111impl_nonzero_hex! {
112 /// 8-bit unsigned nonzero hexadecimal numbers.
113 ///
114 /// ```rust
115 /// use hex_wrapper::NonZeroHex8;
116 ///
117 /// // from random value
118 /// let rand = NonZeroHex8::rand();
119 /// let inner = rand.get();
120 /// assert_eq!(rand.to_string(), format!("{:x}", inner));
121 ///
122 /// // from given value
123 /// let given = NonZeroHex8::new(0xa3).unwrap();
124 /// assert_eq!(given.to_string(), String::from("a3"));
125 ///
126 /// // from string
127 /// let from_str = "a3".parse::<NonZeroHex8>();
128 /// assert_eq!(from_str.unwrap(), NonZeroHex8::new(0xa3).unwrap());
129 /// ```
130 pub struct NonZeroHex8(u8);
131}