Function display_utils::slice [−][src]
pub fn slice<T, R>(object: T, range: R) -> DisplaySlice<T> where
T: Display,
R: RangeBounds<usize>,
Extract a slice from the given Display object, similar to indexing a &str
.
This function will not panic if the slice range is out of bounds, however it will panic when the slice bounds do not lie on char boundaries.
assert_eq!(slice("Hello", 1..).to_string(), "ello"); let parse_int_error = "a".parse::<i32>().unwrap_err(); assert_eq!(slice(parse_int_error, 3..=15).to_string(), "alid digit fo");