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 a new HexString from a string.

Errors

This method fails if the given string is not a valid hexadecimal.

Creates a new HexString without checking the string.

Safety

The string should be a valid hexadecimal string.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.