Struct hexstring::HexString [−][src]
#[repr(transparent)]pub struct HexString<const C: Case>(_);
Expand description
Provides a structured representation of a hexadecimal string.
It is guaranteed to be a valid hexadecimal string, whether initialized from a string or from bytes. A valid [’HexString`] should contain only alphanumerical characters such as :
- ff04ad992c
- FF04AD99C
And must not mix upper and lower alphabetic characters.
Examples
The idiomatic way to construct a HexString is to call HexString::new method with a
string.
use hexstring::{HexString, Case}; let hex = HexString::<{ Case::Upper }>::new("ABCDEF").unwrap();
As the example shown, creating a hexadecimal string is a bit convoluted due to the usage of
const generic parameter.
Two convenient type aliases must be used instead of the raw HexString type :
use hexstring::{UpperHexString, LowerHexString}; let lowercase_hex = LowerHexString::new("abcdef").unwrap(); let uppercase_hex = UpperHexString::new("ABCDEF").unwrap();
HexString has support for conversion from and into array of bytes.
use hexstring::LowerHexString; let expected_bytes = [41, 24, 42]; let hex = LowerHexString::from(expected_bytes); let bytes = Vec::from(hex); assert_eq!(expected_bytes, &bytes[..]);
Implementations
Constructs an UpperHexString from a LowerHexString.
This method performs a copy if the internal string is a string literal.
Constructs a LowerHexString from an UpperHexString.
This method performs a copy if the internal string is a string literal.
Trait Implementations
Auto Trait Implementations
impl<const C: Case> RefUnwindSafe for HexString<C>
impl<const C: Case> UnwindSafe for HexString<C>
Blanket Implementations
Mutably borrows from an owned value. Read more