indexable_str
This Rust library features the IndexableStr
struct. To better understand how strings work in Rust, I decided to create a personal project that parses JSON files. When creating the lexer, I tried a number of ways to correctly index a string to retrieve string slices and char
s. Once I finally started to wrap my head around Rust strings and lifetimes, I created a simple version of IndexableStr
. I found it very convenient to use and it had a bonus of making my code far more readable than the hacky approaches I'd previously tried. Because others may find it useful too, I decided to split IndexableStr
into a separate library project.
See the rustdoc file for the api details.
Examples
// Gets a char from a specified index.
use IndexableStr;
let s = new;
assert_eq!;
// Gets a string slice from a specified range.
use IndexableStr;
let s = new;
assert_eq!
// Parses a string of signed integers, which are separated by whitespace
use Regex;
use IndexableStr;
let text = new;
let signed_integer_pattern: Regex = new.unwrap;
let mut signed_integer_vec: = Vec new;
let mut cursor: usize = 0;
while cursor < text.len
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;