pub struct SyntaxError<E> {
pub kind: SyntaxErrorKind<E>,
/* private fields */
}Expand description
An error while compiling a template string.
A syntax error also contains range information concerning the location in the template string
from which this syntax error was originally parsed. See SyntaxError::locate for more
detail.
Fields§
§kind: SyntaxErrorKind<E>The type of syntax error which occured.
Implementations§
Source§impl<E> SyntaxError<E>
impl<E> SyntaxError<E>
Sourcepub fn locate(&self) -> Range<usize>
pub fn locate(&self) -> Range<usize>
Locate the syntax error inside the original template string.
The returned range is guaranteed to correspond to a valid slice of the original template string, and represents the location at which the error was produced.
§Examples
An expression failed to parse: recover the original expression text.
use mufmt::Template;
let s = "{ not a usize}";
let err = Template::<&str, usize>::compile(s).unwrap_err();
assert_eq!(&s[err.locate()], " not a usize");Get the index of an unclosed delimeter.
let err = Template::<&str, &str>::compile("extra}").unwrap_err();
assert_eq!(err.locate().start, 5);Get all of the trailing characters from an unclosed expression.
let s = " {# 12 }";
let err = Template::<&str, usize>::compile(s).unwrap_err();
assert_eq!(&s[err.locate()], "{# 12 }");§Ranges
The provided ranges depend on the error kind:
| Syntax Error Kind | Range |
|---|---|
SyntaxErrorKind::InvalidExpr | the contents of the expression before trimming whitespace, but not including the brackets. |
SyntaxErrorKind::ExtraBracket | a range of length 1 containing precisely the extra bracket. |
SyntaxErrorKind::UnclosedExpr | a range starting before the expression bracket and terminating at the end of the template string. |
Trait Implementations§
Source§impl<E: Clone> Clone for SyntaxError<E>
impl<E: Clone> Clone for SyntaxError<E>
Source§fn clone(&self) -> SyntaxError<E>
fn clone(&self) -> SyntaxError<E>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<E: Debug> Debug for SyntaxError<E>
impl<E: Debug> Debug for SyntaxError<E>
Source§impl<E, R> From<SyntaxError<E>> for Error<E, R>
impl<E, R> From<SyntaxError<E>> for Error<E, R>
Source§fn from(err: SyntaxError<E>) -> Self
fn from(err: SyntaxError<E>) -> Self
Converts to this type from the input type.
Source§impl<E: PartialEq> PartialEq for SyntaxError<E>
impl<E: PartialEq> PartialEq for SyntaxError<E>
impl<E> StructuralPartialEq for SyntaxError<E>
Auto Trait Implementations§
impl<E> Freeze for SyntaxError<E>where
E: Freeze,
impl<E> RefUnwindSafe for SyntaxError<E>where
E: RefUnwindSafe,
impl<E> Send for SyntaxError<E>where
E: Send,
impl<E> Sync for SyntaxError<E>where
E: Sync,
impl<E> Unpin for SyntaxError<E>where
E: Unpin,
impl<E> UnwindSafe for SyntaxError<E>where
E: UnwindSafe,
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