[][src]Trait bstr::SliceIndex

pub trait SliceIndex: Sealed {
    type Output: ?Sized;
    fn get(self, slice: &BStr) -> Option<&Self::Output>;
fn get_mut(self, slice: &mut BStr) -> Option<&mut Self::Output>;
unsafe fn get_unchecked(self, slice: &BStr) -> &Self::Output;
unsafe fn get_unchecked_mut(self, slice: &mut BStr) -> &mut Self::Output;
fn index(self, slice: &BStr) -> &Self::Output;
fn index_mut(self, slice: &mut BStr) -> &mut Self::Output; }

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

Loading content...

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.

Loading content...

Implementations on Foreign Types

impl SliceIndex for usize[src]

type Output = u8

impl SliceIndex for Range<usize>[src]

type Output = BStr

impl SliceIndex for RangeTo<usize>[src]

type Output = BStr

impl SliceIndex for RangeFrom<usize>[src]

type Output = BStr

impl SliceIndex for RangeFull[src]

type Output = BStr

impl SliceIndex for RangeInclusive<usize>[src]

type Output = BStr

impl SliceIndex for RangeToInclusive<usize>[src]

type Output = BStr

Loading content...

Implementors

Loading content...