Trait libre_pvz_resources::cached::ContainerWithKey

source ·
pub trait ContainerWithKey {
    type Handle;
    type Key: ?Sized;
    type Value: ?Sized;

    // Required methods
    fn get_by_handle(&self, handle: Self::Handle) -> &Self::Value;
    fn get_by_key(&self, key: &Self::Key) -> Option<Self::Handle>;
}
Expand description

Container of key-value pairs, equipped with a handle type to speed up lookup.

Required Associated Types§

source

type Handle

Key for fast lookup: indices into arrays, Handles in Bevy, etc. Should be cheap to clone.

source

type Key: ?Sized

Key type, the actual key for entries in the container.

source

type Value: ?Sized

Value type, usually the entries in the container.

Required Methods§

source

fn get_by_handle(&self, handle: Self::Handle) -> &Self::Value

Access the values in the container by handle. Should be a cheap operation.

source

fn get_by_key(&self, key: &Self::Key) -> Option<Self::Handle>

Get the handle for the specific key, for access and for caching. Potentially expensive, so cache the handle somewhere to avoid calling this method repeatedly (i.e., use Cached).

Implementors§

source§

impl<E: EntryWithKey> ContainerWithKey for SortedSlice<E>
where E::Key: Ord,

§

type Handle = usize

§

type Key = <E as EntryWithKey>::Key

§

type Value = E