Skip to content

Commit

Permalink
Create README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
pacman82 authored Jun 29, 2017
1 parent a07a7d2 commit e3d78f3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
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"));
```

0 comments on commit e3d78f3

Please sign in to comment.