Struct yggdrasil_rt::errors::YggdrasilError
source · pub struct YggdrasilError<R> {
pub variant: YggdrasilErrorKind<R>,
pub location: Range<usize>,
pub source: YggdrasilErrorSource,
}
Expand description
Parse-related error type.
Fields§
§variant: YggdrasilErrorKind<R>
Variant of the error
location: Range<usize>
Location within the input string
source: YggdrasilErrorSource
The file path where the error occurred
Implementations§
source§impl<R: YggdrasilRule> YggdrasilError<R>
impl<R: YggdrasilRule> YggdrasilError<R>
sourcepub fn new_from_span(
variant: YggdrasilErrorKind<R>,
span: TextSpan<'_>
) -> YggdrasilError<R>
pub fn new_from_span( variant: YggdrasilErrorKind<R>, span: TextSpan<'_> ) -> YggdrasilError<R>
Creates Error
from ErrorVariant
and Span
.
§Examples
let error = YggdrasilError::new_from_span(
ErrorKind::ParsingError {
positives: vec![Rule::open_paren],
negatives: vec![Rule::closed_paren],
},
span,
);
println!("{}", error);
sourcepub fn invalid_node(expect: R, span: TextSpan<'_>) -> YggdrasilError<R>
pub fn invalid_node(expect: R, span: TextSpan<'_>) -> YggdrasilError<R>
unable to create node
sourcepub fn missing_rule(expect: R, span: TextSpan<'_>) -> YggdrasilError<R>
pub fn missing_rule(expect: R, span: TextSpan<'_>) -> YggdrasilError<R>
missing rule
sourcepub fn custom_error<S: Display>(
message: S,
span: TextSpan<'_>
) -> YggdrasilError<R>
pub fn custom_error<S: Display>( message: S, span: TextSpan<'_> ) -> YggdrasilError<R>
missing rule
sourcepub fn with_path(self, path: &str) -> YggdrasilError<R>
pub fn with_path(self, path: &str) -> YggdrasilError<R>
Returns Error
variant with path
which is shown when formatted with Display
.
§Examples
YggdrasilError::new_from_offset(
ErrorKind::ParsingError {
positives: vec![Rule::open_paren],
negatives: vec![Rule::closed_paren],
},
pos,
)
.with_path("file.rs");
sourcepub fn get_local_path(&self) -> Option<&str>
pub fn get_local_path(&self) -> Option<&str>
Returns the path set using YggdrasilError::with_path()
.
§Examples
let error = error.with_path("file.rs");
assert_eq!(Some("file.rs"), error.path());
sourcepub fn renamed_rules<F>(self, f: F) -> YggdrasilError<R>
pub fn renamed_rules<F>(self, f: F) -> YggdrasilError<R>
Renames all Rule
s if this is a ParsingError
. It does nothing when called on a
CustomError
.
Useful in order to rename verbose rules or have detailed per-Rule
formatting.
§Examples
YggdrasilError::new_from_offset(
ErrorKind::ParsingError {
positives: vec![Rule::open_paren],
negatives: vec![Rule::closed_paren],
},
pos,
)
.renamed_rules(|rule| match *rule {
Rule::open_paren => "(".to_owned(),
Rule::closed_paren => "closed paren".to_owned(),
});
Trait Implementations§
source§impl<R: Clone> Clone for YggdrasilError<R>
impl<R: Clone> Clone for YggdrasilError<R>
source§fn clone(&self) -> YggdrasilError<R>
fn clone(&self) -> YggdrasilError<R>
Returns a copy 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<R: Debug> Debug for YggdrasilError<R>
impl<R: Debug> Debug for YggdrasilError<R>
source§impl<R: YggdrasilRule> Display for YggdrasilError<R>
impl<R: YggdrasilRule> Display for YggdrasilError<R>
source§impl<R: Hash> Hash for YggdrasilError<R>
impl<R: Hash> Hash for YggdrasilError<R>
source§impl<R: PartialEq> PartialEq for YggdrasilError<R>
impl<R: PartialEq> PartialEq for YggdrasilError<R>
source§fn eq(&self, other: &YggdrasilError<R>) -> bool
fn eq(&self, other: &YggdrasilError<R>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl<R: Eq> Eq for YggdrasilError<R>
impl<R> StructuralPartialEq for YggdrasilError<R>
Auto Trait Implementations§
impl<R> Freeze for YggdrasilError<R>where
R: Freeze,
impl<R> RefUnwindSafe for YggdrasilError<R>where
R: RefUnwindSafe,
impl<R> Send for YggdrasilError<R>where
R: Send,
impl<R> Sync for YggdrasilError<R>where
R: Sync,
impl<R> Unpin for YggdrasilError<R>where
R: Unpin,
impl<R> UnwindSafe for YggdrasilError<R>where
R: 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