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