pub trait DiffableValue: Clone + PartialEq {
Show 16 methods
// Required methods
fn equals(&self, other: &Self) -> bool;
fn value_kind(&self) -> DiffValueKind;
fn as_object(&self) -> Option<Box<dyn Iterator<Item = (&str, &Self)> + '_>>;
fn get_field(&self, key: &str) -> Option<&Self>;
fn as_array(&self) -> Option<&[Self]>
where Self: Sized;
fn as_str(&self) -> Option<&str>;
fn as_bool(&self) -> Option<bool>;
fn as_i64(&self) -> Option<i64>;
fn as_f64(&self) -> Option<f64>;
// Provided methods
fn object_keys(&self) -> Option<Vec<&str>> { ... }
fn array_len(&self) -> Option<usize> { ... }
fn get_element(&self, index: usize) -> Option<&Self>
where Self: Sized { ... }
fn deep_clone(&self) -> Self
where Self: Sized { ... }
fn is_null(&self) -> bool { ... }
fn is_object(&self) -> bool { ... }
fn is_array(&self) -> bool { ... }
}Expand description
Trait for values that can be compared for diffing
This trait provides the interface needed by diff algorithms to:
- Compare values for equality
- Determine value types
- Navigate container contents
§Implementation Notes
equals()should perform deep equality comparisonas_object()returns an iterator over (key, value) pairsas_array()returns a slice of elements
Required Methods§
Sourcefn value_kind(&self) -> DiffValueKind
fn value_kind(&self) -> DiffValueKind
Get the value type classification
Sourcefn as_object(&self) -> Option<Box<dyn Iterator<Item = (&str, &Self)> + '_>>
fn as_object(&self) -> Option<Box<dyn Iterator<Item = (&str, &Self)> + '_>>
Get object entries as an iterator if this is an object
Returns None if this is not an object.
Provided Methods§
Sourcefn object_keys(&self) -> Option<Vec<&str>>
fn object_keys(&self) -> Option<Vec<&str>>
Get object keys as a vector if this is an object
Sourcefn get_element(&self, index: usize) -> Option<&Self>where
Self: Sized,
fn get_element(&self, index: usize) -> Option<&Self>where
Self: Sized,
Get an array element by index
Sourcefn deep_clone(&self) -> Selfwhere
Self: Sized,
fn deep_clone(&self) -> Selfwhere
Self: Sized,
Create a deep clone of this value
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.