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§

source

fn htou(hex: &[u8]) -> Option<Self>

§Hex (Bytes) to Unsigned.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl HexToUnsigned for u8

source§

fn htou(src: &[u8]) -> Option<Self>

§Hex (Bytes) to Unsigned.
source§

impl HexToUnsigned for u16

source§

fn htou(src: &[u8]) -> Option<Self>

§Hex (Bytes) to Unsigned.
source§

impl HexToUnsigned for u32

source§

fn htou(src: &[u8]) -> Option<Self>

§Hex (Bytes) to Unsigned.
source§

impl HexToUnsigned for u64

source§

fn htou(src: &[u8]) -> Option<Self>

§Hex (Bytes) to Unsigned.
source§

impl HexToUnsigned for u128

source§

fn htou(src: &[u8]) -> Option<Self>

§Hex (Bytes) to Unsigned.
source§

impl HexToUnsigned for usize

source§

fn htou(src: &[u8]) -> Option<Self>

§Hex (Bytes) to Unsigned.

Implementors§