Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Null,
    Bool(bool),
    Number(Number),
    String(String),
    Array(Vec<Value>),
    Object(Map),
}
Available on crate feature tree only.
Expand description

A tree: a JSON value whose objects keep their members in the order in which they were written, which is that of the specification for the tree of a message.

It has the variants and the calls of serde_json::Value, and converts to and from one. Two objects are equal when they have the same members, whatever their order, as two JSON objects are. It prints as JSON, its members in their order, and {:#} prints it indented.

use oxirush_utils::tree::{Map, Value};

let mut slice = Map::new();
slice.insert("sst".into(), 1.into());
slice.insert("sd".into(), "0000ff".into());
let tree = Value::Object(slice);
assert_eq!(tree.to_string(), r#"{"sst":1,"sd":"0000ff"}"#);
assert_eq!(tree, serde_json::json!({"sd": "0000ff", "sst": 1}));
assert_eq!(tree["sst"], 1);

Variants§

§

Null

null.

§

Bool(bool)

true or false.

§

Number(Number)

A number.

§

String(String)

A string.

§

Array(Vec<Value>)

A list.

§

Object(Map)

An object, its members in the order in which they were written.

Implementations§

Source§

impl Value

Source

pub fn is_null(&self) -> bool

Whether it is null.

Source

pub fn is_boolean(&self) -> bool

Whether it is true or false.

Source

pub fn is_number(&self) -> bool

Whether it is a number.

Source

pub fn is_u64(&self) -> bool

Whether it is a whole number that a u64 holds.

Source

pub fn is_i64(&self) -> bool

Whether it is a whole number that an i64 holds.

Source

pub fn is_f64(&self) -> bool

Whether it is a number with a fraction or an exponent.

Source

pub fn is_string(&self) -> bool

Whether it is a string.

Source

pub fn is_array(&self) -> bool

Whether it is a list.

Source

pub fn is_object(&self) -> bool

Whether it is an object.

Source

pub fn as_null(&self) -> Option<()>

() for null.

Source

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

The boolean that it is.

Source

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

The number that it is.

Source

pub fn as_u64(&self) -> Option<u64>

The whole number that it is, when a u64 holds it.

Source

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

The whole number that it is, when an i64 holds it.

Source

pub fn as_f64(&self) -> Option<f64>

The number that it is, as an f64.

Source

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

The string that it is.

Source

pub fn as_array(&self) -> Option<&Vec<Value>>

The list that it is.

Source

pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>

The list that it is, to change.

Source

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

The object that it is.

Source

pub fn as_object_mut(&mut self) -> Option<&mut Map>

The object that it is, to change.

Source

pub fn get<I: Index>(&self, index: I) -> Option<&Value>

The member of an object by its name, or the entry of a list by its position.

Source

pub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Value>

The member of an object by its name, or the entry of a list by its position, to change.

Source

pub fn pointer(&self, pointer: &str) -> Option<&Value>

The value at a JSON pointer (RFC 6901), as "/message/protocolIEs/0": the empty pointer is the value itself.

Source

pub fn pointer_mut(&mut self, pointer: &str) -> Option<&mut Value>

The value at a JSON pointer, to change.

Source

pub fn take(&mut self) -> Value

The value, which null takes the place of.

Trait Implementations§

Source§

impl Clone for Value

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 Value

Source§

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

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

impl Default for Value

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Value

Source§

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

The value that a self-describing format writes, the members of an object in the order in which it writes them. A name that an object has twice is refused: JSON leaves what it means open, and a reader of a tree takes no guess.

Source§

impl Display for Value

Source§

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

The JSON text of the tree, its members in their order: compact, or indented with {:#}.

Source§

impl Eq for Value

Source§

impl From<&&str> for Value

Source§

fn from(text: &&str) -> Self

Converts to this type from the input type.
Source§

impl From<&String> for Value

Source§

fn from(text: &String) -> Self

Converts to this type from the input type.
Source§

impl From<&Value> for Value

Source§

fn from(value: &Value) -> Self

Converts to this type from the input type.
Source§

impl From<&Value> for Value

Source§

fn from(value: &Value) -> Self

Converts to this type from the input type.
Source§

impl From<&Value> for Value

Source§

fn from(value: &Value) -> Self

Converts to this type from the input type.
Source§

impl<T: Clone + Into<Value>> From<&[T]> for Value

Source§

fn from(entries: &[T]) -> Self

Converts to this type from the input type.
Source§

impl From<&bool> for Value

Source§

fn from(boolean: &bool) -> Self

Converts to this type from the input type.
Source§

impl From<&f64> for Value

Source§

fn from(number: &f64) -> Self

Converts to this type from the input type.
Source§

impl From<&i8> for Value

Source§

fn from(number: &i8) -> Self

Converts to this type from the input type.
Source§

impl From<&i16> for Value

Source§

fn from(number: &i16) -> Self

Converts to this type from the input type.
Source§

impl From<&i32> for Value

Source§

fn from(number: &i32) -> Self

Converts to this type from the input type.
Source§

impl From<&i64> for Value

Source§

fn from(number: &i64) -> Self

Converts to this type from the input type.
Source§

impl From<&isize> for Value

Source§

fn from(number: &isize) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Value

Source§

fn from(text: &str) -> Self

Converts to this type from the input type.
Source§

impl From<&u8> for Value

Source§

fn from(number: &u8) -> Self

Converts to this type from the input type.
Source§

impl From<&u16> for Value

Source§

fn from(number: &u16) -> Self

Converts to this type from the input type.
Source§

impl From<&u32> for Value

Source§

fn from(number: &u32) -> Self

Converts to this type from the input type.
Source§

impl From<&u64> for Value

Source§

fn from(number: &u64) -> Self

Converts to this type from the input type.
Source§

impl From<&usize> for Value

Source§

fn from(number: &usize) -> Self

Converts to this type from the input type.
Source§

impl From<()> for Value

Source§

fn from((): ()) -> Self

Converts to this type from the input type.
Source§

impl From<Map> for Value

Source§

fn from(members: Map) -> Self

Converts to this type from the input type.
Source§

impl From<Number> for Value

Source§

fn from(number: Number) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Value>> From<Option<T>> for Value

Source§

fn from(value: Option<T>) -> Self

The value, and null for none.

Source§

impl From<String> for Value

Source§

fn from(text: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Value

Source§

fn from(value: Value) -> Self

The same JSON. The members of an object come in the order in which serde_json::Map iterates them: by their names, unless a crate of the program turns on serde_json/preserve_order.

Source§

impl From<Value> for Value

Source§

fn from(value: Value) -> Self

The same JSON. A serde_json::Map keeps the order of the members only where a crate of the program turns on serde_json/preserve_order, and sorts them by their names otherwise.

Source§

impl<T: Into<Value>> From<Vec<T>> for Value

Source§

fn from(entries: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Value>, const N: usize> From<[T; N]> for Value

Source§

fn from(entries: [T; N]) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(boolean: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(number: f64) -> Self

The number, and null for one that JSON has not: an infinity or no number.

Source§

impl From<i8> for Value

Source§

fn from(number: i8) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(number: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(number: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(number: i64) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for Value

Source§

fn from(number: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(number: u8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(number: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(number: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(number: u64) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Value

Source§

fn from(number: usize) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Value>> FromIterator<T> for Value

Source§

fn from_iter<I: IntoIterator<Item = T>>(entries: I) -> Self

A list of the values.

Source§

impl FromStr for Value

Source§

fn from_str(text: &str) -> Result<Self, Self::Err>

The tree that a JSON text writes, its members in the order of the text. A name that an object has twice is refused.

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

impl<I: Index> Index<I> for Value

Source§

fn index(&self, index: I) -> &Value

The member or the entry, and null where there is none.

Source§

type Output = Value

The returned type after indexing.
Source§

impl<I: Index> IndexMut<I> for Value

Source§

fn index_mut(&mut self, index: I) -> &mut Value

The member, which an object takes as null when it has none, and which null takes as an object with that member; or the entry.

§Panics

For a position past the end of a list, and for a value of another kind.

Source§

impl PartialEq for Value

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 PartialEq<&str> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<String> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for Value

Source§

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

Whether the two are the same JSON: objects whatever the order of their members.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for u8

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for u16

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for u32

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for u64

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for usize

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for i8

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for i16

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for i32

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for i64

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for isize

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for f64

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for bool

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for str

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for &str

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for String

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<bool> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<bool> for &Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<f64> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<f64> for &Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<i8> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<i8> for &Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<i16> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<i16> for &Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<i32> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<i32> for &Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<i64> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<i64> for &Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<isize> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<isize> for &Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<str> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<u8> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<u8> for &Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<u16> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<u16> for &Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<u32> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<u32> for &Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<u64> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<u64> for &Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<usize> for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<usize> for &Value

Source§

fn eq(&self, other: &usize) -> 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 Value

Source§

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

The value in any format of serde, the members of an object in their order.

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.