Skip to main content

KeyedGenerator

Trait KeyedGenerator 

Source
pub trait KeyedGenerator<Index>: Clerk<Index, Item: Clone + Default + PartialEq> {
    type Key: Key;

    // Required methods
    fn update(&mut self, data: &Self::Data) -> GeneratorChanges<Index>;
    fn key(&self, data: &Self::Data, index: Index) -> Option<Self::Key>;
    fn generate(&self, data: &Self::Data, key: &Self::Key) -> Self::Item;
}
Expand description

Interface for generators over keyed data

Required Associated Types§

Source

type Key: Key

Key type

All data items should have a stable key so that data items may be tracked through changing queries. This allows focus and selection to correctly track items when the data query or filter changes.

Where the query is fixed, this can just be the Index type.

Required Methods§

Source

fn update(&mut self, data: &Self::Data) -> GeneratorChanges<Index>

Update the generator

This is called by kas::Events::update. It should update self as required reflecting possible data-changes and indicate through the returned GeneratorChanges value the updates required to tokens and views.

Note: this method is called automatically when input data changes. When data owned or referenced by the KeyedGenerator implementation is changed it may be necessary to explicitly update the view controller, e.g. using ConfigCx::update.

This method may be called frequently and without changes to data.

Source

fn key(&self, data: &Self::Data, index: Index) -> Option<Self::Key>

Get a key for a given index, if available

This method should be fast since it may be called repeatedly. This method is only called for index less than the result of Clerk::len.

This may return None even when index is within the query’s range since data may be sparse; in this case the view widget at this index is hidden.

Source

fn generate(&self, data: &Self::Data, key: &Self::Key) -> Self::Item

Generate an item

The key will be the result of Self::key for an index less than Clerk::len.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<Index: Key, G: IndexedGenerator<Index>> KeyedGenerator<Index> for G

Source§

type Key = Index