From e3d78f36c6fed6f9727c930b955fd61e4f7cc08e Mon Sep 17 00:00:00 2001 From: pacman82 Date: Thu, 29 Jun 2017 02:31:46 +0200 Subject: [PATCH] Create README.md --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c286286 --- /dev/null +++ b/README.md @@ -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::(b"42")); +``` +Additional bytes after the number are ignored +```rust +assert_eq!((42,2), atoi::(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::(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::(b"Sadly we do not know the question")); +``` +While signed integer types are supported... +```rust +assert_eq!((42,2), atoi::(b"42")); +``` +... signs currently are not (subject to change in future versions) +``` rust +assert_eq!((0,0), atoi::(b"-42")); +```