Skip to main content

JsonNode

Trait JsonNode 

Source
pub trait JsonNode<'a, F: Json>: Clone {
    type Object: JsonObjectAccess<'a, F, Node = Self>;
    type Array: JsonArrayAccess<'a, F, Node = Self>;

Show 14 methods // Required methods fn as_object(&self) -> Option<Self::Object>; fn as_array(&self) -> Option<Self::Array>; fn as_string(&self) -> Option<Cow<'a, str>>; fn as_number(&self) -> Option<Cow<'a, Number>>; fn as_boolean(&self) -> Option<bool>; fn is_null(&self) -> bool; fn json_type(&self) -> JsonType; fn string_length(&self) -> Option<u64>; fn equals_value(&self, expected: &Value) -> bool; fn to_value(&self) -> Cow<'a, Value>; fn cache_key(&self) -> Option<usize>; // Provided methods fn is_number(&self) -> bool { ... } fn is_string(&self) -> bool { ... } fn container_cache_key(&self) -> Option<usize> { ... }
}
Expand description

One JSON value in some concrete representation; Clone must be cheap (borrow, refcount bump, or machine word copy).

Required Associated Types§

Source

type Object: JsonObjectAccess<'a, F, Node = Self>

Source

type Array: JsonArrayAccess<'a, F, Node = Self>

Required Methods§

Source

fn as_object(&self) -> Option<Self::Object>

Source

fn as_array(&self) -> Option<Self::Array>

Source

fn as_string(&self) -> Option<Cow<'a, str>>

Source

fn as_number(&self) -> Option<Cow<'a, Number>>

Borrowed for serde_json, cheaply owned elsewhere; Number keeps the existing numeric machinery applicable to every representation.

Source

fn as_boolean(&self) -> Option<bool>

Source

fn is_null(&self) -> bool

Source

fn json_type(&self) -> JsonType

The JSON type of this node; numbers always report JsonType::Number (integer distinction is a numeric property, not a type tag).

Source

fn string_length(&self) -> Option<u64>

String length in Unicode code points, without extracting the bytes where the representation allows.

Source

fn equals_value(&self, expected: &Value) -> bool

Deep equality against a schema constant (const/enum); numbers compare mathematically.

Source

fn to_value(&self) -> Cow<'a, Value>

The node as a serde_json::Value; borrowed for serde_json, materialized elsewhere. Intended for cold paths (error construction, annotations).

Source

fn cache_key(&self) -> Option<usize>

Identity for the is_valid result cache; None disables caching for this node.

Provided Methods§

Source

fn is_number(&self) -> bool

Whether this node is a JSON number, answered without materializing the numeric value. Representations where as_number must construct or format (e.g. Python floats under arbitrary precision) override this to skip that cost. Must agree with as_number().is_some().

Source

fn is_string(&self) -> bool

Sugar over JsonNode::json_type, the single source of type classification.

Source

fn container_cache_key(&self) -> Option<usize>

Cache identity restricted to containers, where identities are stable for the whole validation call.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<'a> JsonNode<'a, SerdeJson> for &'a Value

Source§

type Object = &'a Map<String, Value>

Source§

type Array = &'a [Value]

Source§

fn as_object(&self) -> Option<&'a Map<String, Value>>

Source§

fn as_array(&self) -> Option<&'a [Value]>

Source§

fn as_string(&self) -> Option<Cow<'a, str>>

Source§

fn as_number(&self) -> Option<Cow<'a, Number>>

Source§

fn as_boolean(&self) -> Option<bool>

Source§

fn is_null(&self) -> bool

Source§

fn json_type(&self) -> JsonType

Source§

fn string_length(&self) -> Option<u64>

Source§

fn equals_value(&self, expected: &Value) -> bool

Source§

fn to_value(&self) -> Cow<'a, Value>

Source§

fn cache_key(&self) -> Option<usize>

Implementors§