error
import std::encoding::yaml::error; · source
Types
YamlError
type struct YamlError {
kind: YamlErrorKind;
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 | YamlErrorKind | |
line | u64 | 1-indexed line of the offending byte. |
column | u64 | 1-indexed column of the offending byte. |
offset | u64 | 0-indexed byte offset into the source. |
msg | String | Human-readable detail. Owned, and released with the error. |
Constructors
static new(kind: YamlErrorKind, line: u64, column: u64, offset: u64, msg: String) -> YamlError;
static new(kind: YamlErrorKind, line: u64, column: u64, offset: u64, msg: String) -> YamlError;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.
YamlErrorKind
type enum YamlErrorKind with [Eq, Clone] {
UnexpectedEof;
UnexpectedChar;
BadIndentation;
InvalidEscape;
InvalidNumber;
DuplicateKey;
UndefinedAlias;
ExpansionLimit;
DepthExceeded;
UnsupportedTag;
ComplexKey;
MergeKey;
UnsupportedDirective;
MultipleDocuments;
}
Besides malformed text, the kinds name what the reader's safe subset refuses: UnsupportedTag, ComplexKey, MergeKey, UnsupportedDirective, and ExpansionLimit for aliases whose expansion would grow past its bound. MultipleDocuments is more than one document where exactly one was asked for, as Yaml::parse asks; Yaml::parse_all reads them all. label() gives a short diagnostic slug.
Variants
| Variant | Notes |
|---|---|
UnexpectedEof | The input ended inside a node: an unclosed quote, flow collection or escape. |
UnexpectedChar | A character that neither starts nor ends a node where it stands. |
BadIndentation | A line indented where no node can start at that column, or indented with a tab. |
InvalidEscape | A \X escape in a double-quoted scalar that YAML does not define, or one naming no Unicode scalar value. |
InvalidNumber | An integer of the core schema that no 64-bit integer holds. |
DuplicateKey | A mapping with the same key twice. |
UndefinedAlias | An alias *name with no anchor &name before it in its document. |
ExpansionLimit | Aliases that would expand the document past parser::MAX_EXPANDED_NODES nodes. |
DepthExceeded | Collections nested deeper than parser::MAX_DEPTH. |
UnsupportedTag | A tag outside the core schema, or a core-schema tag on a node it does not describe (!!int abc). |
ComplexKey | A complex key: ? key, or a collection or alias used as a key. |
MergeKey | The merge key <<, which the core schema does not define. |
UnsupportedDirective | A directive line (%YAML, %TAG). |
MultipleDocuments | More than one document where exactly one was asked for. |
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 YamlError
implement trait Display for struct YamlError
implement trait Debug for struct YamlError
implement trait Error for struct YamlError
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 YamlError {
kind: YamlErrorKind;
line: u64;
column: u64;
offset: u64;
msg: String;
}Why YAML text could not be read, and where: the failure's kind, its position in the source, and a message for a person to read.
YamlError.kind: YamlErrorKindtype enum YamlErrorKind with [Eq, Clone] {
UnexpectedEof;
UnexpectedChar;
BadIndentation;
InvalidEscape;
InvalidNumber;
DuplicateKey;
UndefinedAlias;
ExpansionLimit;
DepthExceeded;
UnsupportedTag;
ComplexKey;
MergeKey;
UnsupportedDirective;
MultipleDocuments;
}What stopped the reader. A YAML feature outside the subset this reader takes has a kind of its own, so a caller can tell "not YAML" from "YAML this reader refuses".
std::encoding::yaml::errorYamlError.line: u641-indexed line of the offending byte.
YamlError.column: u641-indexed column of the offending byte.
YamlError.offset: u640-indexed byte offset into the source.
YamlError.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 YamlErrorKind with [Eq, Clone] {
UnexpectedEof;
UnexpectedChar;
BadIndentation;
InvalidEscape;
InvalidNumber;
DuplicateKey;
UndefinedAlias;
ExpansionLimit;
DepthExceeded;
UnsupportedTag;
ComplexKey;
MergeKey;
UnsupportedDirective;
MultipleDocuments;
}What stopped the reader. A YAML feature outside the subset this reader takes has a kind of its own, so a caller can tell "not YAML" from "YAML this reader refuses".
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.
YamlErrorKind::UnexpectedEofThe input ended inside a node: an unclosed quote, flow collection or escape.
YamlErrorKind::UnexpectedCharA character that neither starts nor ends a node where it stands.
YamlErrorKind::BadIndentationA line indented where no node can start at that column, or indented with a tab.
YamlErrorKind::InvalidEscapeA \X escape in a double-quoted scalar that YAML does not define, or one naming no Unicode scalar value.
YamlErrorKind::InvalidNumberAn integer of the core schema that no 64-bit integer holds.
YamlErrorKind::DuplicateKeyA mapping with the same key twice.
YamlErrorKind::UndefinedAliasAn alias *name with no anchor &name before it in its document.
YamlErrorKind::ExpansionLimitAliases that would expand the document past parser::MAX_EXPANDED_NODES nodes.
YamlErrorKind::DepthExceededCollections nested deeper than parser::MAX_DEPTH.
YamlErrorKind::UnsupportedTagA tag outside the core schema, or a core-schema tag on a node it does not describe (!!int abc).
YamlErrorKind::ComplexKeyA complex key: ? key, or a collection or alias used as a key.
YamlErrorKind::MergeKeyThe merge key <<, which the core schema does not define.
YamlErrorKind::UnsupportedDirectiveA directive line (%YAML, %TAG).
YamlErrorKind::MultipleDocumentsMore than one document where exactly one was asked for.
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::yaml;yaml: YAML 1.2 text with the core schema, read into and written from the shared data model std::encoding::value::Value.
namespace std::encoding::yaml::error;YamlError: why YAML text could not be read, and where.
module pageYamlError.kind: YamlErrorKindYamlError.msg: StringHuman-readable detail. Owned, and released with the error.
std::encoding::yaml::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 YamlError::new(kind: YamlErrorKind, line: u64, column: u64, offset: u64, msg: String) -> YamlErrorAn 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: YamlErrorKind(parameter) line: u64(parameter) column: u64(parameter) offset: u64(parameter) msg: Stringtype struct YamlError {
kind: YamlErrorKind;
line: u64;
column: u64;
offset: u64;
msg: String;
}Why YAML text could not be read, and where: the failure's kind, its position in the source, and a message for a person to read.
std::encoding::yaml::errorYamlError::describe(&this) -> StrThe human-readable message, borrowed for the error's lifetime; the kind and the position stay available as fields.
std::encoding::yaml::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.
YamlErrorKind::UnsupportedTagA tag outside the core schema, or a core-schema tag on a node it does not describe (!!int abc).
YamlErrorKind::ComplexKeyA complex key: ? key, or a collection or alias used as a key.
YamlErrorKind::MergeKeyThe merge key <<, which the core schema does not define.
YamlErrorKind::ExpansionLimitAliases that would expand the document past parser::MAX_EXPANDED_NODES nodes.
YamlErrorKind::MultipleDocumentsMore than one document where exactly one was asked for.
std::encoding::yaml::errortype struct Yaml {}The YAML text format: reading a Value from YAML text and writing one as YAML text.
static Yaml::parse(text: Str) -> Result<Value, YamlError>Read the one document text holds: Value::Null for text with no document, and YamlErrorKind::MultipleDocuments for text with more than one. The YamlError points at the first byte the reader could not take.
static Yaml::parse_all(text: Str) -> Result<Array<Value>, YamlError>Read every document text holds, in order: those separated by --- and ended by .... Each document's anchors are its own.
YamlErrorKind::label(&this) -> StrA short, stable slug for the kind: "unexpected_eof", "duplicate_key", ...
YamlErrorKind::UnexpectedEofThe input ended inside a node: an unclosed quote, flow collection or escape.
std::encoding::yaml::errorYamlErrorKind::UnexpectedCharA character that neither starts nor ends a node where it stands.
std::encoding::yaml::errorYamlErrorKind::BadIndentationA line indented where no node can start at that column, or indented with a tab.
std::encoding::yaml::errorYamlErrorKind::InvalidEscapeA \X escape in a double-quoted scalar that YAML does not define, or one naming no Unicode scalar value.
YamlErrorKind::InvalidNumberAn integer of the core schema that no 64-bit integer holds.
std::encoding::yaml::errorYamlErrorKind::UndefinedAliasAn alias *name with no anchor &name before it in its document.
YamlErrorKind::DepthExceededCollections 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.