pub struct HexString<C: Case>(/* private fields */);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, Uppercase};
let hex = HexString::<Uppercase>::new("ABCDEF").unwrap();As the example shown, creating a hexadecimal string is a bit convoluted due to the usage of
generic type.
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§
Source§impl<C: Case> HexString<C>
impl<C: Case> HexString<C>
Source§impl HexString<Lowercase>
impl HexString<Lowercase>
Sourcepub fn to_uppercase(self) -> HexString<Uppercase>
pub fn to_uppercase(self) -> HexString<Uppercase>
Constructs an HexString<Uppercase> from a HexString<Lowercase>.
This method performs a copy if the internal string is a string literal.
Source§impl HexString<Uppercase>
impl HexString<Uppercase>
Sourcepub fn to_lowercase(self) -> HexString<Lowercase>
pub fn to_lowercase(self) -> HexString<Lowercase>
Constructs a HexString<Lowercase> from an HexString<Uppercase>.
This method performs a copy if the internal string is a string literal.