pub fn slice<T, R>(object: T, range: R) -> DisplaySlice<T>
Expand description
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");