Stdlibjson
error
import std::json::error; · source
JsonError
type struct JsonError {
kind: JsonErrorKind;
line: u64;
column: u64;
offset: u64;
msg: String;
static new(kind: JsonErrorKind, line: u64, column: u64, offset: u64, msg: String) -> JsonError;
describe(&this) -> Str;
}
Modelled as a kind plus a position plus a message. Branch on kind for programmatic decisions; msg carries the human-readable detail.
| Field / method | Notes |
|---|---|
kind | JsonErrorKind — the closed set of parser failures. |
line / column | 1-indexed, matching editor conventions. |
offset | 0-indexed byte offset into the source. |
msg | Owned String with the detail. |
describe() | Str — the standard accessor every stdlib error exposes. |
JsonErrorKind
type enum JsonErrorKind {
UnexpectedEof;
UnexpectedChar;
InvalidNumber;
InvalidEscape;
InvalidUnicode;
DepthExceeded;
TrailingData;
KeyNotString;
OutOfMemory;
}
implement enum JsonErrorKind {
label(&this) -> string;
}
The closed set of parser failures. label() gives a short diagnostic slug: "unexpected_eof", "invalid_number", and so on.
Trait implementations
implement trait Drop for struct JsonError
implement trait Display for struct JsonError // std::fmt::display
implement trait Debug for struct JsonError // std::fmt::display
JsonError owns its message, which is why it carries a drop.