pub trait BytesToUnsigned: Sized {
    // Required method
    fn btou(src: &[u8]) -> Option<Self>;
}
Expand description

§Bytes to Unsigned.

This trait exposes the method btou which converts (UTF-8) byte slices to proper, unsigned integers. It works just like str::parse and u*::from_str_radix, but faster, particularly for u64 and u128.

Leading zeroes are fine, but the method will return None if the slice is empty, contains non-numeric characters (including + and -), or is too large for the type.

Only little endian architectures are optimized; for big endian machines, this trait just passes through the results of str::parse.

For signed integer parsing, see BytesToSigned;

§Examples

use dactyl::traits::BytesToUnsigned;

assert_eq!(
    u8::btou(b"255"),
    Some(u8::MAX),
);

Required Methods§

source

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

§Bytes to Unsigned.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl BytesToUnsigned for u8

source§

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

§Bytes to Unsigned.
source§

impl BytesToUnsigned for u16

source§

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

§Bytes to Unsigned.
source§

impl BytesToUnsigned for u32

source§

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

§Bytes to Unsigned.
source§

impl BytesToUnsigned for u64

source§

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

§Bytes to Unsigned.
source§

impl BytesToUnsigned for u128

source§

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

§Bytes to Unsigned.
source§

impl BytesToUnsigned for usize

source§

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

§Bytes to Unsigned.
source§

impl BytesToUnsigned for NonZeroU8

source§

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

§Bytes to Unsigned.
source§

impl BytesToUnsigned for NonZeroU16

source§

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

§Bytes to Unsigned.
source§

impl BytesToUnsigned for NonZeroU32

source§

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

§Bytes to Unsigned.
source§

impl BytesToUnsigned for NonZeroU64

source§

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

§Bytes to Unsigned.
source§

impl BytesToUnsigned for NonZeroU128

source§

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

§Bytes to Unsigned.
source§

impl BytesToUnsigned for NonZeroUsize

source§

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

§Bytes to Unsigned.

Implementors§