Skip to main content

Node

Struct Node 

Source
pub struct Node {
    pub value: Value,
    pub span: Option<Span>,
}
Expand description

One value of a document and where it was read from.

Fields§

§value: Value

The value.

§span: Option<Span>

Where it was read from; None for a node built by a program or changed by a fix.

Implementations§

Source§

impl Node

Source

pub const fn new(value: Value) -> Self

A node without a place in a text.

Source

pub const fn null() -> Self

null.

Source

pub const fn bool(value: bool) -> Self

A boolean.

Source

pub fn integer(value: i64) -> Self

An integer.

Source

pub fn float(value: f64) -> Self

A float.

Source

pub const fn number(value: Number) -> Self

A number.

Source

pub fn text(value: impl Into<String>) -> Self

A string.

Source

pub const fn list(items: Vec<Self>) -> Self

An array.

Source

pub fn map<K: Into<String>>( entries: impl IntoIterator<Item = (K, Self)>, ) -> Self

An object from keys and values, in order.

Source

pub const fn kind_name(&self) -> &'static str

The JSON name of the value’s kind: null, boolean, number, string, array or object.

Source

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

The string, when the node is one.

Source

pub const fn as_number(&self) -> Option<&Number>

The number, when the node is one.

Source

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

The boolean, when the node is one.

Source

pub fn as_list(&self) -> Option<&[Self]>

The items, when the node is an array.

Source

pub fn as_map(&self) -> Option<&[Entry]>

The entries, when the node is an object.

Source

pub fn get(&self, key: &str) -> Option<&Self>

The value under key in an object; of a repeated key, the last, as JSON readers keep.

Source

pub fn entry(&self, key: &str) -> Option<&Entry>

The entry under key in an object (the last of a repeated key).

Source

pub fn at(&self, path: &Path) -> Option<&Self>

The node a path names, its root name ignored.

Source

pub fn at_mut(&mut self, path: &Path) -> Option<&mut Self>

The node a path names, for change.

Source

pub fn child(&self, segment: &Segment) -> Option<&Self>

The child a segment names.

Source

pub fn child_mut(&mut self, segment: &Segment) -> Option<&mut Self>

The child a segment names, for change.

Source

pub fn count(&self) -> usize

The number of nodes in the tree, this one included.

Source

pub fn same_document(&self, other: &Self) -> bool

Whether two trees hold the same document, places ignored: keys in order, repeated keys kept, numbers by their spelling.

Source

pub fn same_value(&self, other: &Self) -> bool

Whether two values are equal as JSON values: numbers by value, objects by their last value per key whatever the order.

Source

pub fn without_spans(self) -> Self

The tree with every place removed, as a program would build it.

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Self

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<'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<String> for Node

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Self>> From<Vec<T>> for Node

Source§

fn from(items: Vec<T>) -> 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<i64> for Node

Source§

fn from(value: i64) -> 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 PartialEq for Node

Source§

fn eq(&self, other: &Self) -> 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 Forget for Node

§

impl Freeze for Node

§

impl Move for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node
where RawVecInner: Send,

§

impl Sync for Node
where RawVecInner: Sync,

§

impl Unpin for Node
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for Node

§

impl UnwindSafe for Node
where RawVecInner: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.