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§
type Object: JsonObjectAccess<'a, F, Node = Self>
type Array: JsonArrayAccess<'a, F, Node = Self>
Required Methods§
fn as_object(&self) -> Option<Self::Object>
fn as_array(&self) -> Option<Self::Array>
fn as_string(&self) -> Option<Cow<'a, str>>
Sourcefn as_number(&self) -> Option<Cow<'a, Number>>
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.
fn as_boolean(&self) -> Option<bool>
fn is_null(&self) -> bool
Sourcefn json_type(&self) -> JsonType
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).
Sourcefn string_length(&self) -> Option<u64>
fn string_length(&self) -> Option<u64>
String length in Unicode code points, without extracting the bytes where the representation allows.
Sourcefn equals_value(&self, expected: &Value) -> bool
fn equals_value(&self, expected: &Value) -> bool
Deep equality against a schema constant (const/enum); numbers compare mathematically.
Provided Methods§
Sourcefn is_number(&self) -> bool
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().
Sourcefn is_string(&self) -> bool
fn is_string(&self) -> bool
Sugar over JsonNode::json_type, the single source of type classification.
Sourcefn container_cache_key(&self) -> Option<usize>
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".