Trait 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.

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 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,