HexToSigned

Trait HexToSigned 

Source
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§

Source

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

§Hex (ASCII Bytes) to Signed.

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.

Implementations on Foreign Types§

Source§

impl HexToSigned for i8

Source§

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

§Hex (ASCII Bytes) to Signed.
Source§

impl HexToSigned for i16

Source§

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

§Hex (ASCII Bytes) to Signed.
Source§

impl HexToSigned for i32

Source§

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

§Hex (ASCII Bytes) to Signed.
Source§

impl HexToSigned for i64

Source§

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

§Hex (ASCII Bytes) to Signed.
Source§

impl HexToSigned for i128

Source§

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

§Hex (ASCII Bytes) to Signed.
Source§

impl HexToSigned for isize

Source§

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

§Hex (ASCII Bytes) to Signed.

Implementors§