substring
Substring method for string types.
This crate provides a substring method on Rust string types. The method takes a start and end
character index and returns a string slice of the characters within that range.
The method is provided via the Substring trait which is implemented on the str primitive.
Usage
To use this crate, simply bring the Substring trait into scope and call the substring method on
your string types.
use Substring;
assert_eq!;
Note that the indexing of substrings is based on Unicode Scalar Value. As such, substrings may not always match your intuition:
use Substring;
assert_eq!; // As opposed to "ã".
assert_eq!
The above example occurs because "ã" is technically made up of two UTF-8 scalar values: the letter "a" and a combining tilde.
Performance
As Rust strings are UTF-8 encoded, the algorithm for finding a character substring has temporal complexity O(n), where n is the byte length of the string. This is due to characters not being of predictible byte lengths.
Minimum Supported Rust Version
This crate is guaranteed to compile on stable rustc 1.0.0 and up. Use in a no_std Rust environment
requires stable rustc 1.6.0 and up.