Trait rustemo::Input

source ·
pub trait Input: ToOwned + Index<Range<usize>, Output = Self> {
    // Required methods
    fn context_str(&self, position: usize) -> String;
    fn len(&self) -> usize;
    fn read_file<P: AsRef<Path>>(path: P) -> Result<Self::Owned>;
    fn location_after(&self, location: Location) -> Location;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn slice(
        &self,
        range: Range<usize>
    ) -> &<Self as Index<Range<usize>>>::Output { ... }
    fn start_location() -> Location { ... }
    fn location_span(&self, location: Location) -> Location { ... }
}
Expand description

Input is a sliceable sequence-like type with a concept of length.

This trait must be implemented by all types that should be parsed by Rustemo.

Required Methods§

source

fn context_str(&self, position: usize) -> String

Returns a string context for the given position. Used in debugging outputs.

source

fn len(&self) -> usize

Returns the length of the input.

source

fn read_file<P: AsRef<Path>>(path: P) -> Result<Self::Owned>

Read the file from the given path into owned version of the input.

source

fn location_after(&self, location: Location) -> Location

Given the current location returns the location at the end of self. Location is an input-specific concept. E.g. for text it is line/column.

Provided Methods§

source

fn is_empty(&self) -> bool

Determines if the input is an empty sequence.

source

fn slice(&self, range: Range<usize>) -> &<Self as Index<Range<usize>>>::Output

Implement for types which may cause panic on slicing with full Range (e.g. str).

source

fn start_location() -> Location

source

fn location_span(&self, location: Location) -> Location

Given the current location returns a span starting from the current location and extending over self.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Input for str

source§

fn slice(&self, range: Range<usize>) -> &<Self as Index<Range<usize>>>::Output

Slicing for string works by taking a byte position of range.start and slicing by a range.end-range.start chars.

source§

fn context_str(&self, position: usize) -> String

source§

fn len(&self) -> usize

source§

fn start_location() -> Location

source§

fn location_after(&self, location: Location) -> Location

source§

fn read_file<P: AsRef<Path>>(path: P) -> Result<Self::Owned>

source§

impl Input for [u8]

source§

fn context_str(&self, position: usize) -> String

source§

fn len(&self) -> usize

source§

fn location_after(&self, location: Location) -> Location

source§

fn read_file<P: AsRef<Path>>(path: P) -> Result<Self::Owned>

Implementors§

source§

impl<T, I> Input for T
where Self: Deref<Target = I> + ToOwned<Owned = I::Owned> + Index<Range<usize>, Output = Self>, I: Input + ?Sized,