Skip to main content

DiffableValue

Trait DiffableValue 

Source
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 comparison
  • as_object() returns an iterator over (key, value) pairs
  • as_array() returns a slice of elements

Required Methods§

Source

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

Check deep equality with another value

Source

fn value_kind(&self) -> DiffValueKind

Get the value type classification

Source

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.

Source

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

Get a field value from an object

Source

fn as_array(&self) -> Option<&[Self]>
where Self: Sized,

Get array elements as a slice if this is an array

Source

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

Get as string reference if this is a string

Source

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

Get as boolean if this is a boolean

Source

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

Get as i64 if this is a number

Source

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

Get as f64 if this is a number

Provided Methods§

Source

fn object_keys(&self) -> Option<Vec<&str>>

Get object keys as a vector if this is an object

Source

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

Get array length if this is an array

Source

fn get_element(&self, index: usize) -> Option<&Self>
where Self: Sized,

Get an array element by index

Source

fn deep_clone(&self) -> Self
where Self: Sized,

Create a deep clone of this value

Source

fn is_null(&self) -> bool

Check if this is a null value

Source

fn is_object(&self) -> bool

Check if this is an object

Source

fn is_array(&self) -> bool

Check if this is an array

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.

Implementations on Foreign Types§

Source§

impl DiffableValue for Value

Source§

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

Source§

fn value_kind(&self) -> DiffValueKind

Source§

fn as_object(&self) -> Option<Box<dyn Iterator<Item = (&str, &Value)> + '_>>

Source§

fn get_field(&self, key: &str) -> Option<&Value>

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§