Skip to main content

Input

Trait Input 

Source
pub trait Input:
    Sized
    + Clone
    + Debug
    + Deref<Target = str> {
    // Required method
    fn split_at(self, mid: usize) -> (Self, Self);

    // Provided methods
    fn before(self, index: usize) -> Self { ... }
    fn after(self, index: usize) -> Self { ... }
    fn start(self) -> Self { ... }
    fn end(self) -> Self { ... }
}
Expand description

This trait represents input that can be parsed by a Parser and/or matched by a Pattern.

An Input must be cheaply cloneable, which is why types like Box<str> or String don’t implement this trait.

If you want to create an empty span of the input of a parser, better carve it out of the input to keep the pointer inside it. Even an empty string can provide info on its location in the source code. Input::start & Input::end methods will help you with that.

Required Methods§

Source

fn split_at(self, mid: usize) -> (Self, Self)

A generalisation of str::split_at

Provided Methods§

Source

fn before(self, index: usize) -> Self

Equivalent to self.split_at(mid).0, but can be overridden to provide a more optimal implementation

Source

fn after(self, index: usize) -> Self

Equivalent to self.split_at(mid).1, but can be overriden to provide a more optimal implementation

Source

fn start(self) -> Self

Returns an empty string that points to the start of the input

Source

fn end(self) -> Self

Returns an empty string that points to the end of the input

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Input for &str

Source§

fn split_at(self, mid: usize) -> (Self, Self)

Source§

fn before(self, index: usize) -> Self

Source§

fn after(self, index: usize) -> Self

Implementors§