macro_rules! assert_str_range {
($s:expr, $r:expr) => { ... };
}
Expand description
Asserts that the given range is valid for the given string slice.
The first parameter shall be of a type implementing AsRef<str>
.
The second parameter shall be of a type implementing
the standard library trait RangeBounds<usize>
.
The range is valid if it fits within the slice and its bounds are
on UTF-8 code point boundaries. If either of these checks fails,
panic!
is invoked with a description of the failure.
§Examples
let s = "Hello";
assert_str_range!(s, ..0);
assert_str_range!(s, 5..);
let r = (..=2);
assert_str_range!(s, r);
let (head, tail) = s.as_bytes().split_at(r.end + 1);
ⓘ
let s = "Привет".to_string();
assert_str_range!(s, ..1); // fails due to splitting a UTF-8 sequence