#[non_exhaustive]pub enum Error {
Parse(ParseError),
Evaluation(EvaluationError),
TypeMismatch(TypeMismatchError),
UndefinedVariable(UndefinedVariableError),
}Expand description
Every error the crate answers. The variant is the error’s type, which with the reason is normative where the conformance corpus expects an error (it names the three evaluation types); the message is not.
use predicator_rs::{Error, EvaluationError};
let error = Error::from(EvaluationError::new("empty_stack", "nothing is left"));
assert_eq!(error.type_name(), "EvaluationError");
assert_eq!(error.reason(), "empty_stack");
assert_eq!(error.message(), "nothing is left");
assert_eq!(error.position(), None);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Parse(ParseError)
A text that does not parse.
Evaluation(EvaluationError)
An evaluation failure, or a value refused where it crosses in.
TypeMismatch(TypeMismatchError)
An operand refused on its type.
UndefinedVariable(UndefinedVariableError)
A variable the context does not bind.
Implementations§
Source§impl Error
impl Error
Sourcepub fn type_name(&self) -> &'static str
pub fn type_name(&self) -> &'static str
The error’s type as the corpus spells it: "ParseError",
"EvaluationError", "TypeMismatchError" or
"UndefinedVariableError".
use predicator_rs::compile;
assert_eq!(compile("x >").unwrap_err().type_name(), "ParseError");Sourcepub fn reason(&self) -> &str
pub fn reason(&self) -> &str
The reason: the structured token the corpus names, which is normative.
use predicator_rs::{Context, Options, evaluate};
let refused = evaluate("1 / 0", &Context::new(), &Options::new());
assert_eq!(refused.unwrap_err().reason(), "division_by_zero");Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
The message: a sentence for a person, which is not normative.
use predicator_rs::{Error, TypeMismatchError};
let error = Error::from(TypeMismatchError::new("add", "add takes numbers"));
assert_eq!(error.message(), "add takes numbers");
assert_eq!(error.to_string(), "add takes numbers");Sourcepub fn position(&self) -> Option<Position>
pub fn position(&self) -> Option<Position>
Where in the source the failure is, when that is known.
use predicator_rs::{Context, Options, Position, compile, evaluate};
let parse = compile("x >").unwrap_err();
assert_eq!(parse.position(), Some(Position { line: 1, column: 4 }));
let run = evaluate("1 / 0", &Context::new(), &Options::new()).unwrap_err();
assert_eq!(run.position(), None);Trait Implementations§
impl Eq for Error
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<EvaluationError> for Error
impl From<EvaluationError> for Error
Source§fn from(error: EvaluationError) -> Error
fn from(error: EvaluationError) -> Error
Converts to this type from the input type.
Source§impl From<ParseError> for Error
impl From<ParseError> for Error
Source§fn from(error: ParseError) -> Error
fn from(error: ParseError) -> Error
Converts to this type from the input type.
Source§impl From<TypeMismatchError> for Error
impl From<TypeMismatchError> for Error
Source§fn from(error: TypeMismatchError) -> Error
fn from(error: TypeMismatchError) -> Error
Converts to this type from the input type.
Source§impl From<UndefinedVariableError> for Error
impl From<UndefinedVariableError> for Error
Source§fn from(error: UndefinedVariableError) -> Error
fn from(error: UndefinedVariableError) -> Error
Converts to this type from the input type.
impl StructuralPartialEq for Error
Auto Trait Implementations§
impl Forget for Error
impl Freeze for Error
impl Move for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl UnwindSafe for Error
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