qubit_codec_misc/
hex_codec_config.rs1#[must_use]
16#[derive(Debug, Clone, PartialEq, Eq)]
17pub struct HexCodecConfig {
18 pub(crate) uppercase: bool,
20 pub(crate) prefix: Option<String>,
22 pub(crate) byte_prefix: Option<String>,
24 pub(crate) separator: Option<String>,
26 pub(crate) ignore_ascii_whitespace: bool,
28 pub(crate) ignore_prefix_case: bool,
30}
31
32impl HexCodecConfig {
33 #[inline]
35 pub fn new() -> Self {
36 Self {
37 uppercase: false,
38 prefix: None,
39 byte_prefix: None,
40 separator: None,
41 ignore_ascii_whitespace: false,
42 ignore_prefix_case: false,
43 }
44 }
45
46 #[inline]
48 pub fn with_uppercase(mut self, uppercase: bool) -> Self {
49 self.uppercase = uppercase;
50 self
51 }
52
53 #[inline]
55 pub fn with_prefix(mut self, prefix: impl Into<String>) -> Self {
56 self.prefix = Some(prefix.into());
57 self
58 }
59
60 #[inline]
62 pub fn with_byte_prefix(mut self, prefix: impl Into<String>) -> Self {
63 self.byte_prefix = Some(prefix.into());
64 self
65 }
66
67 #[inline]
69 pub fn with_separator(mut self, separator: impl Into<String>) -> Self {
70 self.separator = Some(separator.into());
71 self
72 }
73
74 #[inline]
76 pub fn with_ignored_ascii_whitespace(mut self, ignore: bool) -> Self {
77 self.ignore_ascii_whitespace = ignore;
78 self
79 }
80
81 #[inline]
83 pub fn with_ignore_prefix_case(mut self, ignore: bool) -> Self {
84 self.ignore_prefix_case = ignore;
85 self
86 }
87
88 #[must_use]
90 #[inline]
91 pub fn is_uppercase(&self) -> bool {
92 self.uppercase
93 }
94
95 #[must_use]
97 #[inline]
98 pub fn prefix(&self) -> Option<&str> {
99 self.prefix.as_deref()
100 }
101
102 #[must_use]
104 #[inline]
105 pub fn byte_prefix(&self) -> Option<&str> {
106 self.byte_prefix.as_deref()
107 }
108
109 #[must_use]
111 #[inline]
112 pub fn separator(&self) -> Option<&str> {
113 self.separator.as_deref()
114 }
115
116 #[must_use]
118 #[inline]
119 pub fn ignores_ascii_whitespace(&self) -> bool {
120 self.ignore_ascii_whitespace
121 }
122
123 #[must_use]
125 #[inline]
126 pub fn ignores_prefix_case(&self) -> bool {
127 self.ignore_prefix_case
128 }
129}
130
131impl Default for HexCodecConfig {
132 #[inline]
133 fn default() -> Self {
134 Self::new()
135 }
136}