Skip to main content

PatchFieldKeyed

Trait PatchFieldKeyed 

Source
pub trait PatchFieldKeyed<K>
where Self: Sized + KeyedAccess<K>, for<'a> &'a Self: IntoIterator,
{ // Required method fn patch_field_keyed( &mut self, new: Self, notify: &mut dyn FnMut(&StorePath), keys: Option<&KeyMap>, key_fn: impl Fn(<&Self as IntoIterator>::Item) -> K, path_at_key: impl Fn(&K) -> Option<StorePath>, ) -> bool where K: Clone + Debug + Send + Sync + PartialEq + Eq + Hash + 'static; }
Expand description

Allows patching a collection in a store field with a new value, after doing a keyed diff.

This takes a key_fn that is applied to each entry in the collection and returns a unique key. Items in the old collection and new collection with the same key are treated as the same value, and the items are patched using PatchField.

The exact notification behavior will depend on the collection type. For example, patching a vector or slice-like type should notify on the collection itself if the order of items changes. If all the same keys are present in the same order, however, the parent collection will not be notified; only the keyed items that have changed.

Required Methods§

Source

fn patch_field_keyed( &mut self, new: Self, notify: &mut dyn FnMut(&StorePath), keys: Option<&KeyMap>, key_fn: impl Fn(<&Self as IntoIterator>::Item) -> K, path_at_key: impl Fn(&K) -> Option<StorePath>, ) -> bool
where K: Clone + Debug + Send + Sync + PartialEq + Eq + Hash + 'static,

Patches a collection with a new value.

Returns true if the structure of the collection changed (items added, removed, or reordered). Individual item changes are notified via the notify callback.

§Arguments
  • new - updated values
  • notify - callback to notify about the update
  • keys - a reference to the KeyMap for the store that’s being patched
  • key_fn - callback returning the key from an item in the collection
  • path_at_key - callback returning a store path for the element in the collection identified by the key

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<K, T> PatchFieldKeyed<K> for Vec<T>
where T: PatchField,

Source§

fn patch_field_keyed( &mut self, new: Self, notify: &mut dyn FnMut(&StorePath), keys: Option<&KeyMap>, key_fn: impl Fn(<&Self as IntoIterator>::Item) -> K, path_at_key: impl Fn(&K) -> Option<StorePath>, ) -> bool
where K: Clone + Debug + Send + Sync + PartialEq + Eq + Hash + 'static,

Source§

impl<K, V> PatchFieldKeyed<K> for BTreeMap<K, V>
where V: PatchField + Clone, K: Eq + Ord + Clone,

Source§

fn patch_field_keyed( &mut self, new: Self, notify: &mut dyn FnMut(&StorePath), keys: Option<&KeyMap>, key_fn: impl Fn(<&Self as IntoIterator>::Item) -> K, path_at_key: impl Fn(&K) -> Option<StorePath>, ) -> bool
where K: Clone + Debug + Send + Sync + PartialEq + Eq + Hash + 'static,

Source§

impl<K, V> PatchFieldKeyed<K> for HashMap<K, V>
where V: PatchField, K: Eq + Hash,

Source§

fn patch_field_keyed( &mut self, new: Self, notify: &mut dyn FnMut(&StorePath), keys: Option<&KeyMap>, key_fn: impl Fn(<&Self as IntoIterator>::Item) -> K, path_at_key: impl Fn(&K) -> Option<StorePath>, ) -> bool
where K: Clone + Debug + Send + Sync + PartialEq + Eq + Hash + 'static,

Implementors§