pub struct ParseError { /* private fields */ }Expand description
A text that does not parse: a source, or a text handed to
tagged::decode. It knows its position.
use predicator_rs::{ParseError, Position};
let error = ParseError::new("malformed_json", "the text ends inside a list")
.with_position(Position { line: 1, column: 3 });
assert_eq!(error.reason(), "malformed_json");
assert_eq!(error.position(), Some(Position { line: 1, column: 3 }));Implementations§
Source§impl ParseError
impl ParseError
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::{ParseError, Position};
let error = ParseError::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::{ParseError, Position};
let error = ParseError::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::{ParseError, Position};
let error = ParseError::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::{ParseError, Position};
let error = ParseError::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::{ParseError, Position};
let error = ParseError::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 ParseError
impl Clone for ParseError
Source§impl Debug for ParseError
impl Debug for ParseError
Source§impl Display for ParseError
impl Display for ParseError
impl Eq for ParseError
Source§impl Error for ParseError
impl Error for ParseError
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<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 PartialEq for ParseError
impl PartialEq for ParseError
impl StructuralPartialEq for ParseError
Auto Trait Implementations§
impl Forget for ParseError
impl Freeze for ParseError
impl Move for ParseError
impl RefUnwindSafe for ParseError
impl Send for ParseError
impl Sync for ParseError
impl Unpin for ParseError
impl UnsafeUnpin for ParseError
impl UnwindSafe for ParseError
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