pub struct HexCodecConfig { /* private fields */ }Expand description
Configuration shared by crate::HexCodec encoding and decoding
operations.
The configuration is intentionally separate from the codec value so the same formatting and decoding policy can be reused by multiple codecs.
§Examples
use qubit_codec_misc::HexCodec;
use qubit_codec_misc::HexCodecConfig;
let config = HexCodecConfig::new()
.with_uppercase(true)
.with_prefix("0x");
let codec = HexCodec::from_config(config);
assert_eq!(codec.encode(&[0x1f, 0x8b]), "0x1F8B");Implementations§
Source§impl HexCodecConfig
impl HexCodecConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a lowercase configuration without prefixes or separators.
§Returns
A configuration with lowercase encoding and all optional formatting tokens disabled.
Sourcepub fn is_uppercase(&self) -> bool
pub fn is_uppercase(&self) -> bool
Returns whether encoded digits use uppercase characters.
§Returns
true if uppercase hexadecimal digits are used during encoding.
Sourcepub fn prefix(&self) -> Option<&str>
pub fn prefix(&self) -> Option<&str>
Returns the configured whole-output prefix.
§Returns
Some contains the prefix written before the encoded bytes; None
means no whole-output prefix is configured.
Sourcepub fn byte_prefix(&self) -> Option<&str>
pub fn byte_prefix(&self) -> Option<&str>
Returns the configured per-byte prefix.
§Returns
Some contains the prefix written before each encoded byte; None
means no per-byte prefix is configured.
Sourcepub fn separator(&self) -> Option<&str>
pub fn separator(&self) -> Option<&str>
Returns the configured separator.
§Returns
Some contains the separator written between bytes; None means no
separator is configured.
Sourcepub fn ignores_ascii_whitespace(&self) -> bool
pub fn ignores_ascii_whitespace(&self) -> bool
Returns whether ASCII whitespace is ignored while decoding.
§Returns
true if ASCII whitespace is skipped during decoding.
Sourcepub fn ignores_prefix_case(&self) -> bool
pub fn ignores_prefix_case(&self) -> bool
Returns whether configured prefixes are matched case-insensitively.
§Returns
true if ASCII letter case is ignored when matching prefixes.
Sourcepub fn with_uppercase(self, uppercase: bool) -> Self
pub fn with_uppercase(self, uppercase: bool) -> Self
Sourcepub fn with_prefix(self, prefix: impl Into<String>) -> Self
pub fn with_prefix(self, prefix: impl Into<String>) -> Self
Sourcepub fn with_byte_prefix(self, prefix: impl Into<String>) -> Self
pub fn with_byte_prefix(self, prefix: impl Into<String>) -> Self
Sourcepub fn with_separator(self, separator: impl Into<String>) -> Self
pub fn with_separator(self, separator: impl Into<String>) -> Self
Sets a separator between encoded bytes.
With a non-empty separator, the two hexadecimal digits of each byte must be contiguous. Ignored ASCII whitespace may surround complete byte tokens and configured separators, but does not replace a required prefix or separator. Without a non-empty separator, ignored whitespace may also occur between the two digits of a byte. A complete structural token is matched before skipping additional whitespace. Non-whitespace separators are matched exactly; a whitespace-only separator still requires whitespace between bytes, and ignored ASCII whitespace may consume additional adjacent whitespace. Prefix case folding does not apply to separators.
§Parameters
separator: Text written between adjacent encoded bytes.
§Returns
The updated configuration.
Sourcepub fn with_ignored_ascii_whitespace(self, ignore: bool) -> Self
pub fn with_ignored_ascii_whitespace(self, ignore: bool) -> Self
Sets whether ASCII whitespace is ignored while decoding.
With a non-empty separator, the two hexadecimal digits of each byte must be contiguous. Ignored ASCII whitespace may surround complete byte tokens and configured separators, but does not replace a required prefix or separator. Without a non-empty separator, ignored whitespace may also occur between the two digits of a byte. A complete structural token is matched before skipping additional whitespace. Non-whitespace separators are matched exactly; a whitespace-only separator still requires whitespace between bytes, and ignored ASCII whitespace may consume additional adjacent whitespace. Prefix case folding does not apply to separators.
§Parameters
ignore: Whether ASCII whitespace is skipped during decoding.
§Returns
The updated configuration.