serde_hex/config.rs
1//! `SerHex` configuration variants.
2//!
3//! This module is a collection of marker types which implement
4//! the possible combinations of config values described by the
5//! `HexConf` trait. All config values are supplied with associated
6//! functions that are marked with `#[inline]`. This ensures that
7//! the compiler will (usually) optimize away all configuration
8//! checks.
9
10/// Trait for supplying configuration to `SerHex`.
11/// This trait takes no `self` parameters, as it is
12/// intended to be applied unit structs. All default
13/// implementation are set to `false`.
14pub trait HexConf {
15 /// function indicating whether to use compact
16 /// (as apposed to strict) representation.
17 #[inline]
18 fn compact() -> bool {
19 false
20 }
21 /// function indicating whether to prefixing (`0x`).
22 #[inline]
23 fn withpfx() -> bool {
24 false
25 }
26 /// function indicating whether to use capital letters (`A-F`).
27 #[inline]
28 fn withcap() -> bool {
29 false
30 }
31}
32
33/// Config indicating a strict representation
34/// with no capiltaization and no prefixing.
35pub struct Strict;
36impl HexConf for Strict {}
37
38/// Config indicating a strict representation
39/// with prefixing but no capitalization.
40pub struct StrictPfx;
41impl HexConf for StrictPfx {
42 #[inline]
43 fn withpfx() -> bool {
44 true
45 }
46}
47
48/// Config indicating a strict representation
49/// with capitalization but no prefixing.
50pub struct StrictCap;
51impl HexConf for StrictCap {
52 #[inline]
53 fn withcap() -> bool {
54 true
55 }
56}
57
58/// Config indicating a strict representation
59/// with capitalization and prefixing.
60pub struct StrictCapPfx;
61impl HexConf for StrictCapPfx {
62 #[inline]
63 fn withpfx() -> bool {
64 true
65 }
66 #[inline]
67 fn withcap() -> bool {
68 true
69 }
70}
71
72/// Config indicating compact representation
73/// with no capitalization and no prefixing.
74pub struct Compact;
75impl HexConf for Compact {
76 #[inline]
77 fn compact() -> bool {
78 true
79 }
80}
81
82/// Config indicating compact representation
83/// with prefixing but no capitalization.
84pub struct CompactPfx;
85impl HexConf for CompactPfx {
86 #[inline]
87 fn compact() -> bool {
88 true
89 }
90 #[inline]
91 fn withpfx() -> bool {
92 true
93 }
94}
95
96/// Config indicating compact representation
97/// with capitalization but no prefixing.
98pub struct CompactCap;
99impl HexConf for CompactCap {
100 #[inline]
101 fn compact() -> bool {
102 true
103 }
104 #[inline]
105 fn withcap() -> bool {
106 true
107 }
108}
109
110/// Config indicating compact representation
111/// with capitalization and prefixing.
112pub struct CompactCapPfx;
113impl HexConf for CompactCapPfx {
114 #[inline]
115 fn compact() -> bool {
116 true
117 }
118 #[inline]
119 fn withcap() -> bool {
120 true
121 }
122 #[inline]
123 fn withpfx() -> bool {
124 true
125 }
126}