Trait dactyl::traits::BytesToUnsigned
source · 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§
Object Safety§
This trait is not object safe.