error
import std::encoding::toml::error; · source
Types
TomlError
type struct TomlError {
kind: TomlErrorKind;
line: u64;
column: u64;
offset: u64;
msg: String;
}
A kind, a position and a message, the same shape as JsonError. line and column are 1-indexed and offset is a 0-indexed byte offset into the source.
Properties
| Property | Type | Notes |
|---|---|---|
kind | TomlErrorKind | |
line | u64 | 1-indexed line of the offending byte; 0 for a value the writer refused. |
column | u64 | 1-indexed column of the offending byte; 0 for a value the writer refused. |
offset | u64 | 0-indexed byte offset into the source. |
msg | String | Human-readable detail. Owned, and released with the error. |
Constructors
static new(kind: TomlErrorKind, line: u64, column: u64, offset: u64, msg: String) -> TomlError;
static new(kind: TomlErrorKind, line: u64, column: u64, offset: u64, msg: String) -> TomlError;An error of kind at the 1-indexed line and column, byte offset from the start of the source, explained by msg, which the error takes ownership of.
Methods
describe(&this) -> Str;
describe(&this) -> Str;The human-readable message, borrowed for the error's lifetime; the kind and the position stay available as fields.
TomlErrorKind
type enum TomlErrorKind with [Eq, Clone] {
UnexpectedEof;
UnexpectedChar;
InvalidEscape;
InvalidNumber;
InvalidDateTime;
DuplicateKey;
TableRedefined;
DepthExceeded;
NotRepresentable;
}
DuplicateKey and TableRedefined are TOML's own rules on defining keys and tables; NotRepresentable is the writer's refusal of a value TOML cannot spell: a document that is not a table, or a null in an array. label() gives a short diagnostic slug.
Variants
| Variant | Notes |
|---|---|
UnexpectedEof | The input ended inside a value: an unclosed string, array or inline table, or a key with no value. |
UnexpectedChar | A character that cannot stand where it does: a key or value malformed, a control character, a missing line break. |
InvalidEscape | A \X escape TOML does not define, or one naming no Unicode scalar value. |
InvalidNumber | A number TOML does not spell that way (01, 1__0, .5), or an integer no 64-bit signed integer holds. |
InvalidDateTime | A date or time with a field out of its range (2023-02-30, 24:00:00) or a malformed one. |
DuplicateKey | A key given a value twice in one table. |
TableRedefined | A table defined twice, a table header naming a key that holds a value, or a table extended in a way TOML forbids: by a header after its dotted keys, or by dotted keys after its header. |
DepthExceeded | Arrays, inline tables and tables nested deeper than parser::MAX_DEPTH. |
NotRepresentable | A value the writer cannot write as TOML: a document that is not a table, or a null in an array. |
Methods
label(&this) -> Str;
label(&this) -> Str;A short, stable slug for the kind: "unexpected_eof", "duplicate_key", ...
Trait implementations
implement trait Drop for struct TomlError
implement trait Display for struct TomlError
implement trait Debug for struct TomlError
implement trait Error for struct TomlError
type struct Name { ... }
type enum Name { ... }
type trait Name { ... }
type union Name { ... }Begins a type declaration; the keyword that follows says which kind. On its own, type Name = Existing; declares an alias.
type struct Name {
field: Type;
method(&this) -> Ret { ... }
}A value type with named fields and optional methods. Structs live on the stack and are passed by value. Fields are public by default and may carry = default values; methods take their receiver as &this, mut &this, or this.
type struct TomlError {
kind: TomlErrorKind;
line: u64;
column: u64;
offset: u64;
msg: String;
}Why TOML text could not be read or a value written, and where: the failure's kind, its position in the source (0 for the writer's), and a message for a person to read.
TomlError.kind: TomlErrorKindtype enum TomlErrorKind with [Eq, Clone] {
UnexpectedEof;
UnexpectedChar;
InvalidEscape;
InvalidNumber;
InvalidDateTime;
DuplicateKey;
TableRedefined;
DepthExceeded;
NotRepresentable;
}What stopped the reader, or the writer.
std::encoding::toml::errorTomlError.line: u641-indexed line of the offending byte; 0 for a value the writer refused.
TomlError.column: u641-indexed column of the offending byte; 0 for a value the writer refused.
TomlError.offset: u640-indexed byte offset into the source.
TomlError.msg: StringHuman-readable detail. Owned, and released with the error.
type struct String<A = GlobalAllocator> {}Owned, growable UTF-8 text. It dereferences to Str, the read-only view most text functions take, so every Str method reads a String too (s.contains(...), s.split(...)); as_str hands the view out.
type enum Name {
Unit,
Payload(T),
Named { x: i32 },
}An algebraic data type. Variants may be bare or carry a tuple or struct payload, and a match on an enum must cover every variant. Name::Variant names a variant; methods are added with implement enum Name { ... }.
type enum TomlErrorKind with [Eq, Clone] {
UnexpectedEof;
UnexpectedChar;
InvalidEscape;
InvalidNumber;
InvalidDateTime;
DuplicateKey;
TableRedefined;
DepthExceeded;
NotRepresentable;
}What stopped the reader, or the writer.
type struct Point with [Eq, Clone, Debug] { .. }Asks the compiler to generate implementations of the listed traits for the type, each working through its fields or variants in declaration order. The derivable traits are Eq, Ord, Hash, Clone, Debug, Default, ToValue and FromValue, and the text formats' FromJson, ToJson, FromYaml, ToYaml, FromToml and ToToml. The clause comes after the name and its parameters, before where.
type trait Eq<Rhs = This> {
equals(&this, other: &Rhs) -> boolean;
}Types that support value equality with a value of Rhs, which is the type itself unless an implementation names another: implement trait Eq for Str compares two Strs, and implement trait Eq<string> for Str a Str with a string.
type trait Clone {
clone(&this) -> This;
}A type whose values can be duplicated into independent copies. A type takes it with with [Clone] on its declaration, or by implementing clone by hand.
TomlErrorKind::UnexpectedEofThe input ended inside a value: an unclosed string, array or inline table, or a key with no value.
TomlErrorKind::UnexpectedCharA character that cannot stand where it does: a key or value malformed, a control character, a missing line break.
TomlErrorKind::InvalidEscapeA \X escape TOML does not define, or one naming no Unicode scalar value.
TomlErrorKind::InvalidNumberA number TOML does not spell that way (01, 1__0, .5), or an integer no 64-bit signed integer holds.
TomlErrorKind::InvalidDateTimeA date or time with a field out of its range (2023-02-30, 24:00:00) or a malformed one.
TomlErrorKind::DuplicateKeyA key given a value twice in one table.
TomlErrorKind::TableRedefinedA table defined twice, a table header naming a key that holds a value, or a table extended in a way TOML forbids: by a header after its dotted keys, or by dotted keys after its header.
TomlErrorKind::DepthExceededArrays, inline tables and tables nested deeper than parser::MAX_DEPTH.
TomlErrorKind::NotRepresentableA value the writer cannot write as TOML: a document that is not a table, or a null in an array.
import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
namespace std::encoding::toml;toml: TOML 1.0 text, read into and written from the shared data model std::encoding::value::Value.
namespace std::encoding::toml::error;TomlError: why TOML text could not be read or a value could not be written as TOML, and where.
module pageTomlError.line: u641-indexed line of the offending byte; 0 for a value the writer refused.
std::encoding::toml::errorTomlError.column: u641-indexed column of the offending byte; 0 for a value the writer refused.
std::encoding::toml::errorTomlError.kind: TomlErrorKindTomlError.msg: StringHuman-readable detail. Owned, and released with the error.
std::encoding::toml::errorstatic name(param: Type) -> Ret { ... }A method that belongs to the type rather than an instance, called as Type::name(..). For structs, static new(..) returning a struct literal is the idiomatic constructor.
static TomlError::new(kind: TomlErrorKind, line: u64, column: u64, offset: u64, msg: String) -> TomlErrorAn error of kind at the 1-indexed line and column, byte offset from the start of the source, explained by msg, which the error takes ownership of.
(parameter) kind: TomlErrorKind(parameter) line: u64(parameter) column: u64(parameter) offset: u64(parameter) msg: Stringtype struct TomlError {
kind: TomlErrorKind;
line: u64;
column: u64;
offset: u64;
msg: String;
}Why TOML text could not be read or a value written, and where: the failure's kind, its position in the source (0 for the writer's), and a message for a person to read.
std::encoding::toml::errorTomlError::describe(&this) -> StrThe human-readable message, borrowed for the error's lifetime; the kind and the position stay available as fields.
std::encoding::toml::error&this
mut &this
thisThe receiver of a method. Its first parameter declares how the method takes it: &this borrows read-only, mut &this borrows exclusively, and this / mut this move the value in and consume it. In the body, this.field reaches the members.
type struct Str {}A read-only view of UTF-8 text owned elsewhere: a string literal, a String, a file's bytes. Copying a Str copies the view, not the text, and it is valid only while what it views is. Str::new("text") views a literal; String.as_str() views a String.
TomlErrorKind::TableRedefinedA table defined twice, a table header naming a key that holds a value, or a table extended in a way TOML forbids: by a header after its dotted keys, or by dotted keys after its header.
std::encoding::toml::errorTomlErrorKind::NotRepresentableA value the writer cannot write as TOML: a document that is not a table, or a null in an array.
std::encoding::toml::errorTomlErrorKind::label(&this) -> StrA short, stable slug for the kind: "unexpected_eof", "duplicate_key", ...
TomlErrorKind::UnexpectedEofThe input ended inside a value: an unclosed string, array or inline table, or a key with no value.
std::encoding::toml::errorTomlErrorKind::UnexpectedCharA character that cannot stand where it does: a key or value malformed, a control character, a missing line break.
std::encoding::toml::errorTomlErrorKind::InvalidEscapeA \X escape TOML does not define, or one naming no Unicode scalar value.
TomlErrorKind::InvalidNumberA number TOML does not spell that way (01, 1__0, .5), or an integer no 64-bit signed integer holds.
TomlErrorKind::InvalidDateTimeA date or time with a field out of its range (2023-02-30, 24:00:00) or a malformed one.
TomlErrorKind::DepthExceededArrays, inline tables and tables nested deeper than parser::MAX_DEPTH.
implement struct Name { ... }
implement trait Trait for Type { ... }
implement u64 { ... }Adds methods to a type outside its declaration. implement struct T (or enum, or a bare primitive) opens an inherent block; implement trait Tr for T supplies a trait's methods for one type. Resolution is at compile time - no dynamic dispatch.
implement trait Trait for Type { ... }Introduces a trait implementation: the block supplies, for one concrete type, the method bodies the trait requires.
language referencetype trait Drop {
drop(mut &this) -> void;
}A type that releases something when a value of it ends: memory, a file handle, a lock. The compiler calls drop once when an owned value goes out of scope; release a value early with mem::drop(value).
implement trait Trait for Type { ... }Names the type a trait implementation is for. The block that follows supplies the bodies the trait requires.
language referencetype trait Display {
fmt(&this, f: mut &Formatter) -> Result<(), FormatError>;
to_string(&this) -> String;
}How a value reads to a person: what {x} in an f-string and println write. Implement it for a type a user sees.
type trait Debug {
fmt(&this, f: mut &Formatter) -> Result<(), FormatError>;
}How a value reads to a programmer: what {x:?} writes, and {x:#?} over several lines. with [Debug] on a declaration writes it field by field.
type trait Error : Display, Debug {
source(&this) -> Option<virtual &Error>;
}An error: a message for a person through Display, a fuller form through Debug, and the error it was caused by, if it keeps one.