atoi 0.1.0

Parse integers directly from `[u8]` slices in safe code
Documentation

atoi-rs

Parse integers directly from [u8] slices in safe code

Examples

Parsing to digits from a slice

use atoi::atoi;
assert_eq!((42,2), atoi::<u32>(b"42"));

Additional bytes after the number are ignored

assert_eq!((42,2), atoi::<u32>(b"42 is the answer to life, the universe and everything"));

The second number indicates how many bytes were 'used'

assert_eq!((12345,5), atoi::<u32>(b"12345 and now to something completly different...));

(0,0) is returned if the slice does not start with a digit

assert_eq!((0,0), atoi::<u32>(b"Sadly we do not know the question"));

While signed integer types are supported...

assert_eq!((42,2), atoi::<i32>(b"42"));

... signs currently are not (subject to change in future versions)

assert_eq!((0,0), atoi::<i32>(b"-42"));