#string #substr #str #slice

no-std substring

A substring method for string types

16 stable releases

Uses old Rust 2015

1.4.5 Feb 4, 2021
1.4.4 Jan 31, 2021
1.4.0 Oct 26, 2020

#207 in Text processing

Download history 66933/week @ 2023-10-31 56861/week @ 2023-11-07 65817/week @ 2023-11-14 60135/week @ 2023-11-21 68591/week @ 2023-11-28 57432/week @ 2023-12-05 50547/week @ 2023-12-12 39728/week @ 2023-12-19 11622/week @ 2023-12-26 26995/week @ 2024-01-02 29176/week @ 2024-01-09 28513/week @ 2024-01-16 31250/week @ 2024-01-23 35791/week @ 2024-01-30 32206/week @ 2024-02-06 28674/week @ 2024-02-13

132,875 downloads per month
Used in 159 crates (54 directly)


57 lines


GitHub Workflow Status codecov.io crates.io docs.rs MSRV License

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 containing the characters within that range.

The method is provided via the Substring trait which is implemented on the str primitive.


To use this crate, simply bring the Substring trait into scope and call the substring method on your string types.

use substring::Substring;

assert_eq!("hello, world!".substring(7, 12), "world");

Note that the indexing of substrings is based on Unicode Scalar Value. As such, substrings may not always match your intuition:

use substring::Substring;

assert_eq!("".substring(0, 1), "a");  // As opposed to "ã".
assert_eq!("".substring(1, 2), "\u{0303}")

The above example occurs because "ã" is technically made up of two UTF-8 scalar values: the letter "a" and a combining tilde.


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.


This project is licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps