docs

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 NabionError

A 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).

  • pub const fn new(msg: str) -> NabionError§

    Source

    An error with message msg, at no position yet.

  • pub const fn within(self, seg: str) -> NabionError§

    Source

    self one level down: seg (.name, [3]) goes in front of the path.

  • pub const fn message(self) -> str§

    Source

    What went wrong, without the position Display adds.

  • pub const fn line(self) -> u32§

    Source

    1-based line in the document; 0 when the value did not come from text.

  • pub const fn column(self) -> u32§

    Source

    1-based column (code points); 0 as for line.

  • pub const fn path(self) -> str§

    Source

    The failing part (.servers[2].port); empty at the root.

Trait implementations 3
  • impl Display for NabionError
  • impl Debug for NabionError
  • impl Error for NabionError

Enums

ValueSource

pub enum Value

A 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.

Trait implementations 7

Traits

ToNabionSource

pub trait ToNabion

A Nabi value as NABION.

FromNabionSource

pub trait FromNabion

A Nabi value from NABION; the target type decides how v reads.

  • fn from_nabion(v: Value) throws (NabionError) -> Self§

    Source

    Read v as this type; throws NabionError when its shape does not match.

  • const fn from_missing() throws (NabionError) -> Self§

    Source

    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.