[−][src]Trait bstr::SliceIndex
A trait that parameterizes the different types of indexing a byte string.
In general, this trait makes it possible to define generic routines like
get
that can accept either single positions or ranges, and return single
bytes or slices, respectively.
This trait is sealed such that callers cannot implement it. In general, callers should not need to interact with this trait directly unless you're defining generic functions that index or slice a byte string.
Associated Types
type Output: ?Sized
The output type returned by methods. For indexing by position, this
is always a single byte (u8
). For ranges, this is always a slice
(BStr
).
Required methods
fn get(self, slice: &BStr) -> Option<&Self::Output>
Returns a shared reference to the output at this location, if in bounds.
fn get_mut(self, slice: &mut BStr) -> Option<&mut Self::Output>
Returns a mutable reference to the output at this location, if in bounds.
unsafe fn get_unchecked(self, slice: &BStr) -> &Self::Output
Returns a shared reference to the output at this location, without performing any bounds checking.
unsafe fn get_unchecked_mut(self, slice: &mut BStr) -> &mut Self::Output
Returns a mutable reference to the output at this location, without performing any bounds checking.
fn index(self, slice: &BStr) -> &Self::Output
Returns a shared reference to the output at this location, panicking if out of bounds.
fn index_mut(self, slice: &mut BStr) -> &mut Self::Output
Returns a mutable reference to the output at this location, panicking if out of bounds.