pub trait HexToSigned: Sized {
// Required method
fn htoi(hex: &[u8]) -> Option<Self>;
}Expand description
§Hex (ASCII Bytes) to Unsigned.
This trait exposes the method htou to decode an ASCII byte slice of
hex values into a proper unsigned integer.
This method returns None if the slice is empty or the resulting value is
too big for the type.
(Excessive leading zeroes are fine and will simply be stripped.)
For signed integers, see HexToSigned.
§Examples
use dactyl::traits::HexToSigned;
assert_eq!(i8::htoi(b"fB"), Some(-5));
assert_eq!(i8::htoi(b"0FB"), Some(-5));
// These are no good.
assert!(i8::htoi(&[]).is_none()); // Empty.
assert!(i8::htoi(b"-fb").is_none()); // "-"
assert!(i8::htoi(b" FB ").is_none()); // Whitespace.
assert!(i8::htoi(b"FFB").is_none()); // Too big.Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.