pub trait RawStrIndex {
    type Output: ?Sized;

    // Required methods
    fn get(self, s: &RawStr) -> Option<&Self::Output>;
    fn get_mut(self, s: &mut RawStr) -> Option<&mut Self::Output>;
    unsafe fn get_unchecked(self, s: &RawStr) -> &Self::Output;
    unsafe fn get_unchecked_mut(self, s: &mut RawStr) -> &mut Self::Output;
    fn index(self, s: &RawStr) -> &Self::Output;
    fn index_mut(self, s: &mut RawStr) -> &mut Self::Output;
}
Expand description

The equivalent of SliceIndex for RawStr.

Usage

Normally, this trait is not used directly. Its functionality is exposed through Index and the get methods of RawStr.

Implementors

RawStrIndex is automatically implemented for all that implement SliceIndex<[u8]>:

  • a SliceIndex<[u8], Output=[u8]> automatically implements RawStrIndex<Output=RawStr>, and
  • a SliceIndex<[u8], Output=u8> automatically implements RawStrIndex<Output=u8>.

Examples

let s = RawStr::from_str("hello world");
let hello: &RawStr = &s[..5]; // This is a slice.
let space: u8 = s[5]; // This is a single byte
assert_eq!(hello, "hello");
assert_eq!(space, b' ');

Required Associated Types§

source

type Output: ?Sized

RawStr (for ranges) or u8 (for single indexes).

Required Methods§

source

fn get(self, s: &RawStr) -> Option<&Self::Output>

Get the range or byte from the given &RawStr.

source

fn get_mut(self, s: &mut RawStr) -> Option<&mut Self::Output>

Get the (mutable) range or byte from the given &mut RawStr.

source

unsafe fn get_unchecked(self, s: &RawStr) -> &Self::Output

Like get, but unsafe and unchecked.

source

unsafe fn get_unchecked_mut(self, s: &mut RawStr) -> &mut Self::Output

Like get_mut, but unsafe and unchecked.

source

fn index(self, s: &RawStr) -> &Self::Output

Like get, but panics on failure.

source

fn index_mut(self, s: &mut RawStr) -> &mut Self::Output

Like get_mut, but panics on failure.

Implementors§

source§

impl<I> RawStrIndex for Iwhere I: SliceIndex<[u8]>, I::Output: RawStrIndexOutput + 'static,

§

type Output = <<I as SliceIndex<[u8]>>::Output as RawStrIndexOutput>::Output