DiffKey

Trait DiffKey 

Source
pub trait DiffKey {
    type Key<'a>: PartialEq
       where Self: 'a;

    // Required method
    fn key(&self) -> Self::Key<'_>;
}
Expand description

A trait that must be implemented by any type T that is part of a Vec<T> being diffed.

The value for Key should be unique to that element in the list (akin to React in JS land). It allows the diff algorithm to detect whether elements have been changed, moved or completely replaced.

If there is no sensible value to use as the key, consider making a dummy ID to attach to T. Otherwise, it is acceptable to use a null value like (), but this may cause the diff algorithm to run slowly and generate unnecessarily large diffs

Required Associated Types§

Source

type Key<'a>: PartialEq where Self: 'a

Required Methods§

Source

fn key(&self) -> Self::Key<'_>

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 DiffKey for &'static str

Source§

type Key<'a> = &'static str

Source§

fn key(&self) -> Self::Key<'_>

Source§

impl DiffKey for bool

Source§

type Key<'a> = bool

Source§

fn key(&self) -> Self::Key<'_>

Source§

impl DiffKey for f32

Source§

type Key<'a> = f32

Source§

fn key(&self) -> Self::Key<'_>

Source§

impl DiffKey for f64

Source§

type Key<'a> = f64

Source§

fn key(&self) -> Self::Key<'_>

Source§

impl DiffKey for i8

Source§

type Key<'a> = i8

Source§

fn key(&self) -> Self::Key<'_>

Source§

impl DiffKey for i16

Source§

type Key<'a> = i16

Source§

fn key(&self) -> Self::Key<'_>

Source§

impl DiffKey for i32

Source§

type Key<'a> = i32

Source§

fn key(&self) -> Self::Key<'_>

Source§

impl DiffKey for i64

Source§

type Key<'a> = i64

Source§

fn key(&self) -> Self::Key<'_>

Source§

impl DiffKey for u8

Source§

type Key<'a> = u8

Source§

fn key(&self) -> Self::Key<'_>

Source§

impl DiffKey for u16

Source§

type Key<'a> = u16

Source§

fn key(&self) -> Self::Key<'_>

Source§

impl DiffKey for u32

Source§

type Key<'a> = u32

Source§

fn key(&self) -> Self::Key<'_>

Source§

impl DiffKey for u64

Source§

type Key<'a> = u64

Source§

fn key(&self) -> Self::Key<'_>

Source§

impl DiffKey for String

Source§

type Key<'a> = &'a String

Source§

fn key(&self) -> Self::Key<'_>

Implementors§