pub struct Ctx<'a> { /* private fields */ }
Expand description
A parsing context for UTF-8 input strings that can store error messages.
This context maintains a reference to the input data and optionally stores error information during parsing operations.
Implementations§
Source§impl<'a> Ctx<'a>
impl<'a> Ctx<'a>
Sourcepub fn static_error(&mut self, err: &'static str)
pub fn static_error(&mut self, err: &'static str)
Records an error message if no error is currently stored.
Sourcepub fn current_error(&self) -> Option<&str>
pub fn current_error(&self) -> Option<&str>
Returns the current error message, if any.
Sourcepub fn try_extend_lifetime(&self, text: &str) -> Option<&'a str>
pub fn try_extend_lifetime(&self, text: &str) -> Option<&'a str>
Attempts to extend the lifetime of a text fragment if it belongs to the input buffer.
§Example
let input = String::from("Hello, World!");
let ctx = Ctx::new(&input);
let slice = &input[0..5];
if let Some(extended) = ctx.try_extend_lifetime(slice) {
assert_eq!(extended, "Hello");
}
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Ctx<'a>
impl<'a> RefUnwindSafe for Ctx<'a>
impl<'a> Send for Ctx<'a>
impl<'a> Sync for Ctx<'a>
impl<'a> Unpin for Ctx<'a>
impl<'a> UnwindSafe for Ctx<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more