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§
sourcefn context_str(&self, position: usize) -> String
fn context_str(&self, position: usize) -> String
Returns a string context for the given position. Used in debugging outputs.
sourcefn read_file<P: AsRef<Path>>(path: P) -> Result<Self::Owned>
fn read_file<P: AsRef<Path>>(path: P) -> Result<Self::Owned>
Read the file from the given path into owned version of the input.
sourcefn location_after(&self, location: Location) -> Location
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§
sourcefn slice(&self, range: Range<usize>) -> &<Self as Index<Range<usize>>>::Output
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
).
fn start_location() -> Location
sourcefn location_span(&self, location: Location) -> Location
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
impl Input for str
source§fn slice(&self, range: Range<usize>) -> &<Self as Index<Range<usize>>>::Output
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.