Source

Trait Source 

Source
pub trait Source<Cursor> {
    type Slice<'source>: Slice<'source>
       where Self: 'source;

    // Required methods
    fn is_empty(&self) -> bool;
    fn len(&self) -> Cursor;
    fn slice<'a, R>(&self, range: R) -> Option<Self::Slice<'_>>
       where R: RangeBounds<&'a Cursor>,
             Cursor: 'a;
    fn is_boundary(&self, index: Cursor) -> bool;

    // Provided method
    fn find_boundary(&self, index: Cursor) -> Cursor { ... }
}
Expand description

The source trait for lexers

Required Associated Types§

Source

type Slice<'source>: Slice<'source> where Self: 'source

A type this Source can be sliced into.

Required Methods§

Source

fn is_empty(&self) -> bool

Returns true if the source is empty.

Source

fn len(&self) -> Cursor

Length of the source

Source

fn slice<'a, R>(&self, range: R) -> Option<Self::Slice<'_>>
where R: RangeBounds<&'a Cursor>, Cursor: 'a,

Get a slice of the source at given range. This is analogous to slice::get(range).

Source

fn is_boundary(&self, index: Cursor) -> bool

Check if index is valid for this Source, that is:

  • It’s not larger than the byte length of the Source.
  • (str only) It doesn’t land in the middle of a UTF-8 code point.

Provided Methods§

Source

fn find_boundary(&self, index: Cursor) -> Cursor

For &str sources attempts to find the closest char boundary at which source can be sliced, starting from index.

For binary sources (&[u8]) this should just return index back.

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 Source<usize> for str

Source§

type Slice<'source> = &'source str where Self: 'source

Source§

fn is_empty(&self) -> bool

Source§

fn len(&self) -> usize

Source§

fn slice<'a, R>(&self, range: R) -> Option<Self::Slice<'_>>
where R: RangeBounds<&'a usize>,

Source§

fn is_boundary(&self, index: usize) -> bool

Source§

impl Source<usize> for BStr

Available on crate feature bstr only.
Source§

type Slice<'a> = &'a [u8] where Self: 'a

Source§

fn is_empty(&self) -> bool

Source§

fn len(&self) -> usize

Source§

fn slice<'a, R>(&self, range: R) -> Option<Self::Slice<'_>>
where R: RangeBounds<&'a usize>, usize: 'a,

Source§

fn is_boundary(&self, index: usize) -> bool

Source§

impl Source<usize> for Bytes

Available on crate feature bytes only.
Source§

type Slice<'a> = Bytes where Self: 'a

Source§

fn is_empty(&self) -> bool

Source§

fn len(&self) -> usize

Source§

fn slice<'a, R>(&self, range: R) -> Option<Self::Slice<'_>>
where R: RangeBounds<&'a usize>,

Source§

fn is_boundary(&self, index: usize) -> bool

Source§

impl Source<usize> for HipByt<'_>

Available on crate feature hipstr only.
Source§

type Slice<'a> = HipByt<'a, Arc> where Self: 'a

Source§

fn is_empty(&self) -> bool

Source§

fn len(&self) -> usize

Source§

fn slice<'a, R>(&self, range: R) -> Option<Self::Slice<'_>>
where R: RangeBounds<&'a usize>, usize: 'a,

Source§

fn is_boundary(&self, index: usize) -> bool

Source§

impl Source<usize> for [u8]

Source§

type Slice<'source> = &'source [u8] where Self: 'source

Source§

fn is_empty(&self) -> bool

Source§

fn len(&self) -> usize

Source§

fn slice<'a, R>(&self, range: R) -> Option<Self::Slice<'_>>
where R: RangeBounds<&'a usize>, usize: 'a,

Source§

fn is_boundary(&self, index: usize) -> bool

Source§

impl<'h> Source<usize> for HipStr<'h>

Available on crate feature hipstr only.
Source§

type Slice<'a> = HipStr<'a, Arc> where Self: 'a

Source§

fn is_empty(&self) -> bool

Source§

fn len(&self) -> usize

Source§

fn slice<'a, R>(&self, range: R) -> Option<Self::Slice<'_>>
where R: RangeBounds<&'a usize>, usize: 'a,

Source§

fn is_boundary(&self, index: usize) -> bool

Implementors§