Trait SubsliceOffset

Source
pub trait SubsliceOffset {
    // Required method
    fn subslice_offset<'a>(&'a self, inner: &'a Self) -> Option<usize>;
}

Required Methods§

Source

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);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl SubsliceOffset for str

Source§

fn subslice_offset<'a>(&'a self, inner: &'a Self) -> Option<usize>

Source§

impl<T> SubsliceOffset for [T]

Source§

fn subslice_offset<'a>(&'a self, inner: &'a Self) -> Option<usize>

Implementors§