Trait dactyl::traits::HexToUnsigned
source · pub trait HexToUnsigned: Sized {
// Required method
fn htou(hex: &[u8]) -> Option<Self>;
}
Expand description
§Hex (Bytes) to Unsigned.
This trait exposes the method htou
which converts Hex byte slices to
proper, unsigned integers. It works just like u*::from_str_radix
, but
faster, particularly for u64
and u128
.
Decoding is case-insensitive and padding-agnostic; slice lengths may be
anything between 1..=std::mem::size_of::<Self>()*2
.
Invalid slices, overflows, etc., will result in None
being returned.
For signed integers, see HexToSigned
.
§Examples
use dactyl::traits::HexToUnsigned;
assert_eq!(u8::htou(b"d"), Some(13));
assert_eq!(u8::htou(b"D"), Some(13));
assert_eq!(u8::htou(b"0d"), Some(13));
assert_eq!(u8::htou(b"0D"), Some(13));
Required Methods§
Object Safety§
This trait is not object safe.