std::nabion
API 参考只有英文版,由标准库源代码中的英文文档注释生成。
NABION (Nabi Object Notation, .nabion): one value
written in Nabi literal syntax.
parse reads a document into a Value, to_str writes the
canonical form, and ToNabion / FromNabion (with #[derive(Nabion)])
map Nabi types to and from Value. The reader is a small lexer plus a
recursive descent over the literal subset (the compiler's parser is not
reachable at run time).
Decode errors carry a path (.limits["cpu"], .tags[1]); from_str
turns it into line:col by re-reading the document and stopping at
that path, so the happy path keeps no positions.
Structs
NabionErrorSource
pub struct NabionErrorA read or decode error. line / col (1-based, code points) are 0
when the value did not come from text (T::from_nabion(v) directly);
path names the failing part (.servers[2].port, empty at the root).
An error with message
msg, at no position yet.selfone level down:seg(.name,[3]) goes in front of the path.What went wrong, without the position
Displayadds.1-based line in the document; 0 when the value did not come from text.
1-based column (code points); 0 as for
line.The failing part (
.servers[2].port); empty at the root.
Enums
ValueSource
pub enum ValueA NABION value. { k: v } with identifier keys is a Struct without
a name; { "k": v } (any value keys) and {} are a Dict. A path
with :: is a Variant (E::V, E::V(a, k: b), E::V { f: v });
Name(a, b) (a tuple struct) is a Variant with a one-segment path.
Sourcepub fn to_str(§self) throws (NabionError) -> str The canonical text: 4-space indent, one line when it fits in 100 columns, otherwise one element per line with a trailing comma. A float with no NABION form (NaN, infinity, past the
f64range) is thrown, with its path.What kind of value this is, for messages (
integer,struct, ..).
Traits
ToNabionSource
pub trait ToNabionA Nabi value as NABION.
selfas a NABION value.
FromNabionSource
pub trait FromNabionA Nabi value from NABION; the target type decides how v reads.
Sourcefn from_nabion(§v: Value) throws (NabionError) -> Self Read
vas this type; throwsNabionErrorwhen its shape does not match.
Sourceconst fn from_missing(§) throws (NabionError) -> Self A struct field of this type that the document leaves out: an error, except
T | none(none).
Functions
from_value_anySource
pub fn from_value_any(t: TypeInfo, v: Value) throws (NabionError) -> any A t made from v, as to_value_any writes it. A struct field the
value leaves out takes its default.
to_value_anySource
pub fn to_value_any(v: any) throws (NabionError) -> Value v as a Value, read through its type's description: Inspect
structs and enums, lists, dicts, sums and primitives.
parseSource
pub fn parse(s: str) throws (NabionError) -> Value Read one NABION document.
to_strSource
pub fn to_str<T: ToNabion>(v: T) throws (NabionError) -> str v in canonical NABION. A float with no NABION form (NaN,
infinity, past the f64 range) is thrown, with its path.
to_str_flatSource
pub fn to_str_flat<T: ToNabion>(v: T) throws (NabionError) -> str to_str on one line, whatever its width.
from_strSource
pub fn from_str<T: FromNabion>(s: str) throws (NabionError) -> T Read a document as a T; errors carry the line:col of the part that
did not fit.
to_valueSource
pub const fn to_value<T: ToNabion>(x: T) -> Value x as a Value (to_value::<T>(x) keeps a T | none field whole).
from_valueSource
pub const fn from_value<T: FromNabion>(v: Value) throws (NabionError) -> T v as a T.