pub struct JsonSyntaxError { /* private fields */ }Expand description
A JSON syntax error with a zero-based byte offset and one-based source coordinates. Its column counts UTF-8 characters; CRLF is one line break, while LF and standalone CR each also start a new line.
§Examples
use qubit_json::decode::{JsonSyntaxError, JsonSyntaxErrorReason};
let error = JsonSyntaxError::new(
0,
1,
1,
JsonSyntaxErrorReason::UnexpectedEnd,
);
assert_eq!(error.line(), 1);
assert_eq!(error.reason(), JsonSyntaxErrorReason::UnexpectedEnd);Implementations§
Source§impl JsonSyntaxError
impl JsonSyntaxError
Sourcepub const fn new(
offset: usize,
line: usize,
column: usize,
reason: JsonSyntaxErrorReason,
) -> Self
pub const fn new( offset: usize, line: usize, column: usize, reason: JsonSyntaxErrorReason, ) -> Self
Creates a syntax error from a source position and stable reason.
§Parameters
offset- Zero-based byte offset at which the error was observed.line- One-based source line containing the error.column- One-based UTF-8 character column containing the error.reason- Stable classification of the lexical failure.
§Returns
A syntax error containing the supplied location and classification.
Sourcepub const fn context(&self) -> Option<JsonDecodeContext>
pub const fn context(&self) -> Option<JsonDecodeContext>
Returns the grammar location where the error occurred, when known.
Sourcepub const fn offset(&self) -> usize
pub const fn offset(&self) -> usize
Returns the zero-based byte offset.
§Returns
The zero-based byte offset at which the error was observed.
Sourcepub const fn column(&self) -> usize
pub const fn column(&self) -> usize
Returns the one-based UTF-8 character column.
§Returns
The one-based UTF-8 character column containing the error.
Sourcepub const fn reason(&self) -> JsonSyntaxErrorReason
pub const fn reason(&self) -> JsonSyntaxErrorReason
Sourcepub const fn with_context(self, context: JsonDecodeContext) -> Self
pub const fn with_context(self, context: JsonDecodeContext) -> Self
Returns this error with the supplied grammar context.
§Parameters
context- Grammar location associated with this syntax error.
Trait Implementations§
Source§impl Clone for JsonSyntaxError
impl Clone for JsonSyntaxError
impl Copy for JsonSyntaxError
Source§impl Debug for JsonSyntaxError
impl Debug for JsonSyntaxError
Source§impl Display for JsonSyntaxError
impl Display for JsonSyntaxError
impl Eq for JsonSyntaxError
Source§impl Error for JsonSyntaxError
impl Error for JsonSyntaxError
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 PartialEq for JsonSyntaxError
impl PartialEq for JsonSyntaxError
impl StructuralPartialEq for JsonSyntaxError
Auto Trait Implementations§
impl Forget for JsonSyntaxError
impl Freeze for JsonSyntaxError
impl Move for JsonSyntaxError
impl RefUnwindSafe for JsonSyntaxError
impl Send for JsonSyntaxError
impl Sync for JsonSyntaxError
impl Unpin for JsonSyntaxError
impl UnsafeUnpin for JsonSyntaxError
impl UnwindSafe for JsonSyntaxError
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