Trait subslice_offset::SubsliceOffset
source · [−]pub trait SubsliceOffset {
fn subslice_offset<'a>(&'a self, inner: &'a Self) -> Option<usize>;
}
Required Methods
fn subslice_offset<'a>(&'a self, inner: &'a Self) -> Option<usize>
fn subslice_offset<'a>(&'a self, inner: &'a Self) -> Option<usize>
Returns the byte offset of an inner slice relative to an enclosing outer slice.
Examples
let string = "a\nb\nc";
let lines: Vec<&str> = string.lines().collect();
assert_eq!(string.subslice_offset(lines[0]), Some(0)); // &"a"
assert_eq!(string.subslice_offset(lines[1]), Some(2)); // &"b"
assert_eq!(string.subslice_offset(lines[2]), Some(4)); // &"c"
assert_eq!(string.subslice_offset("other!"), None);