Function mut_str::char_slice

source ·
pub fn char_slice<R: RangeBounds<usize>>(s: &str, range: R) -> Option<&str>
Expand description

Slice a str in units of UTF-8 characters.

use mut_str::char_slice;

let s = "Hello, World!";

let hello = char_slice(s, ..5).unwrap();
assert_eq!(hello, "Hello");

let world = char_slice(s, 7..12).unwrap();
assert_eq!(world, "World");