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§
Required Methods§
Sourcefn slice<'a, R>(&self, range: R) -> Option<Self::Slice<'_>>where
R: RangeBounds<&'a Cursor>,
Cursor: 'a,
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).
Sourcefn is_boundary(&self, index: Cursor) -> bool
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. - (
stronly) It doesn’t land in the middle of a UTF-8 code point.
Provided Methods§
Sourcefn find_boundary(&self, index: Cursor) -> Cursor
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.