pub trait Input<'a>: Clone {
Show 15 methods
// Required methods
fn cur(&self) -> Option<u8>;
fn peek(&self) -> Option<u8>;
fn peek_ahead(&self) -> Option<u8>;
unsafe fn bump_bytes(&mut self, n: usize);
fn cur_as_char(&self) -> Option<char>;
fn is_at_start(&self) -> bool;
fn cur_pos(&self) -> BytePos;
fn last_pos(&self) -> BytePos;
unsafe fn slice(&mut self, start: BytePos, end: BytePos) -> &'a str;
fn uncons_while<F>(&mut self, f: F) -> &'a str
where F: FnMut(char) -> bool;
unsafe fn reset_to(&mut self, to: BytePos);
fn is_str(&self, s: &str) -> bool;
// Provided methods
fn cur_as_ascii(&self) -> Option<u8> { ... }
fn is_byte(&self, c: u8) -> bool { ... }
unsafe fn eat_byte(&mut self, c: u8) -> bool { ... }
}Required Methods§
Sourcefn peek_ahead(&self) -> Option<u8>
fn peek_ahead(&self) -> Option<u8>
Returns the byte after the next byte without consuming anything.
Sourceunsafe fn bump_bytes(&mut self, n: usize)
unsafe fn bump_bytes(&mut self, n: usize)
Advances the input by exactly n bytes.
Unlike bump(), this does not calculate UTF-8 character boundaries.
§Safety
- This should be called only when
cur()returnsSome. i.e. when the Input is not empty. nshould be the number of bytes of the current character.
Sourcefn cur_as_char(&self) -> Option<char>
fn cur_as_char(&self) -> Option<char>
Returns the current position as a UTF-8 char for cases where we need full character processing (identifiers, strings, etc). Returns None if at end of input or if the bytes don’t form valid UTF-8.
fn is_at_start(&self) -> bool
fn cur_pos(&self) -> BytePos
fn last_pos(&self) -> BytePos
Sourceunsafe fn slice(&mut self, start: BytePos, end: BytePos) -> &'a str
unsafe fn slice(&mut self, start: BytePos, end: BytePos) -> &'a str
§Safety
- start should be less than or equal to end.
- start and end should be in the valid range of input.
Sourcefn uncons_while<F>(&mut self, f: F) -> &'a str
fn uncons_while<F>(&mut self, f: F) -> &'a str
Takes items from stream, testing each one with predicate. returns the range of items which passed predicate.
Provided Methods§
Sourcefn cur_as_ascii(&self) -> Option<u8>
fn cur_as_ascii(&self) -> Option<u8>
Returns the current byte as ASCII if it’s valid ASCII (0x00-0x7F). Returns None if it’s end of input or if the byte is not ASCII.
Sourcefn is_byte(&self, c: u8) -> bool
fn is_byte(&self, c: u8) -> bool
Check if the current byte equals the given byte.
c should typically be an ASCII byte for performance.
Sourceunsafe fn eat_byte(&mut self, c: u8) -> bool
unsafe fn eat_byte(&mut self, c: u8) -> bool
Implementors can override the method to make it faster.
§Safety
c must be ASCII (i.e., c <= 0x7F). Passing a non-ASCII byte may
advance the input into the middle of a multi-byte UTF-8 sequence,
which would violate the UTF-8 invariant of the underlying &str.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".