Skip to main content

Node

Enum Node 

Source
pub enum Node {
    Null,
    Bool(bool),
    Int(i64),
    UInt(u64),
    Float(f64),
    String(String),
    Expr(String),
    Array(Vec<Node>),
    Object(NodeMap),
}
Expand description

A dynamically typed value that round-trips through YAML and JSON while preserving object key order.

Entry config read from a file is stored as a Node; plugins receive it wrapped in a cordis::Value and recover it with downcast::<Node>(). Unlike serde_json::Value or serde_yaml_ng::Value, object keys keep their file order, which keeps serialized output stable and friendly to diffs and file watchers.

Variants§

§

Null

Absent value (null / ~).

§

Bool(bool)

Boolean literal.

§

Int(i64)

Signed integer.

§

UInt(u64)

Unsigned integer outside i64 range.

§

Float(f64)

Floating-point number.

§

String(String)

String literal (subject to ${{ ... }} interpolation).

§

Expr(String)

A !!js expression scalar, kept verbatim and unevaluated: it round-trips through YAML (!!js <expr>) and only takes effect when config is handed to a plugin. Produced by the crate’s own YAML dialect parser (crate::yaml); serde paths (JSON) never yield it and serialize it as its raw text.

§

Array(Vec<Node>)

Array of nodes.

§

Object(NodeMap)

Ordered object.

Implementations§

Source§

impl Node

Source

pub fn as_str(&self) -> Option<&str>

Return the string contents, or None for any other node kind.

Source

pub fn as_i64(&self) -> Option<i64>

Return the integer value, or None for any other node kind.

Source

pub fn as_bool(&self) -> Option<bool>

Return the boolean value, or None for any other node kind.

Source

pub fn as_object(&self) -> Option<&NodeMap>

Return the object entries, or None for any other node kind.

Source

pub fn as_array(&self) -> Option<&[Node]>

Return the array items, or None for any other node kind.

Source

pub fn is_null(&self) -> bool

Whether this node is Node::Null.

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Node

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Node

Source§

fn default() -> Node

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Node

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&str> for Node

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<IndexMap<String, Node>> for Node

Source§

fn from(value: NodeMap) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Node

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Node>> for Node

Source§

fn from(value: Vec<Node>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Node

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Node

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Node

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Node

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Node

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Node

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for Node

Source§

fn from(value: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Node

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Node

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Node

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Node

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Node

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<(String, Node)> for Node

Source§

fn from_iter<I: IntoIterator<Item = (String, Node)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Index<&str> for Node

Indexes object keys, panicking only when the node is not an object.

Missing keys yield Node::Null, which keeps assertions on parsed config concise (assert_eq!(node["missing"], Node::Null)).

Source§

type Output = Node

The returned type after indexing.
Source§

fn index(&self, key: &str) -> &Node

Performs the indexing (container[index]) operation. Read more
Source§

impl PartialEq for Node

Source§

fn eq(&self, other: &Node) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Node

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Node

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

§

impl UnwindSafe for Node

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.