-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# atoi-rs | ||
Parse integers directly from `[u8]` slices in safe code | ||
|
||
# Examples | ||
|
||
Parsing to digits from a slice | ||
```rust | ||
use atoi::atoi; | ||
assert_eq!((42,2), atoi::<u32>(b"42")); | ||
``` | ||
Additional bytes after the number are ignored | ||
```rust | ||
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' | ||
```rust | ||
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 | ||
```rust | ||
assert_eq!((0,0), atoi::<u32>(b"Sadly we do not know the question")); | ||
``` | ||
While signed integer types are supported... | ||
```rust | ||
assert_eq!((42,2), atoi::<i32>(b"42")); | ||
``` | ||
... signs currently are not (subject to change in future versions) | ||
``` rust | ||
assert_eq!((0,0), atoi::<i32>(b"-42")); | ||
``` |