pub struct TypeMismatchError { /* private fields */ }Expand description
An operand an operation refused on its type. The reason names the operation.
use predicator_rs::TypeMismatchError;
let error = TypeMismatchError::new("add", "add takes two numbers");
assert_eq!(error.reason(), "add");Implementations§
Source§impl TypeMismatchError
impl TypeMismatchError
Sourcepub fn new(reason: impl Into<String>, message: impl Into<String>) -> Self
pub fn new(reason: impl Into<String>, message: impl Into<String>) -> Self
An error with a reason (the corpus’s token) and a message (a sentence for a person), at no position.
use predicator_rs::{TypeMismatchError, Position};
let error = TypeMismatchError::new("some_reason", "a sentence");
assert_eq!(error.reason(), "some_reason");
assert_eq!(error.position(), None);Sourcepub fn with_position(self, position: Position) -> Self
pub fn with_position(self, position: Position) -> Self
The same error at position.
use predicator_rs::{TypeMismatchError, Position};
let error = TypeMismatchError::new("some_reason", "a sentence");
let at = Position { line: 2, column: 3 };
assert_eq!(error.with_position(at).position(), Some(at));Sourcepub fn reason(&self) -> &str
pub fn reason(&self) -> &str
The reason: the structured token the corpus names, which is normative.
use predicator_rs::{TypeMismatchError, Position};
let error = TypeMismatchError::new("some_reason", "a sentence");
assert_eq!(error.reason(), "some_reason");Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
The message: a sentence for a person, which is not normative.
use predicator_rs::{TypeMismatchError, Position};
let error = TypeMismatchError::new("some_reason", "a sentence");
assert_eq!(error.message(), "a sentence");
assert_eq!(error.to_string(), "a sentence");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::{TypeMismatchError, Position};
let error = TypeMismatchError::new("some_reason", "a sentence");
assert_eq!(error.position(), None);
let at = Position { line: 1, column: 1 };
assert_eq!(error.with_position(at).position(), Some(at));Trait Implementations§
Source§impl Clone for TypeMismatchError
impl Clone for TypeMismatchError
Source§impl Debug for TypeMismatchError
impl Debug for TypeMismatchError
Source§impl Display for TypeMismatchError
impl Display for TypeMismatchError
impl Eq for TypeMismatchError
Source§impl Error for TypeMismatchError
impl Error for TypeMismatchError
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<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 PartialEq for TypeMismatchError
impl PartialEq for TypeMismatchError
impl StructuralPartialEq for TypeMismatchError
Auto Trait Implementations§
impl Forget for TypeMismatchError
impl Freeze for TypeMismatchError
impl Move for TypeMismatchError
impl RefUnwindSafe for TypeMismatchError
impl Send for TypeMismatchError
impl Sync for TypeMismatchError
impl Unpin for TypeMismatchError
impl UnsafeUnpin for TypeMismatchError
impl UnwindSafe for TypeMismatchError
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