Trait Container

Source
pub trait Container {
    type Key;
    type Value;

    // Required methods
    fn values(&self) -> &[Self::Value];
    fn selectors(&self) -> &BTreeMap<Self::Key, Selector<Self::Value>>;
    fn with_preset<V, P>(
        preset: &P,
        selectors: BTreeMap<Self::Key, Selector<Self::Value>>,
    ) -> Self
       where V: Into<Self::Value>,
             P: Preset<Value = V>;
    fn with_presets<V, P>(
        presets: &[P],
        selectors: BTreeMap<Self::Key, Selector<Self::Value>>,
    ) -> Self
       where V: Into<Self::Value>,
             P: Preset<Value = V>;

    // Provided methods
    fn len(&self) -> usize { ... }
    fn is_empty(&self) -> bool { ... }
    fn by_index(&self, index: usize) -> Option<&Self::Value> { ... }
    fn get<K: Into<Self::Key>>(&self, key: K) -> Option<&Self::Value>
       where Self::Key: Ord { ... }
}
Expand description

A container of a slice of values (usually a vector) that are accessible by index, but also by means of a mapping of keys to selectors. The selector states whether to use the key’s order to access the values, a given index or even a completely overridden value that is not in the list of values. Values are re-used in a carousel fashion using the modulo operator for indices or orders that are out of bounds.

Required Associated Types§

Required Methods§

Source

fn values(&self) -> &[Self::Value]

The slice of values that are used by default.

Source

fn selectors(&self) -> &BTreeMap<Self::Key, Selector<Self::Value>>

The mapping of key to selector. A selector is an entry’s index or an override.

Source

fn with_preset<V, P>( preset: &P, selectors: BTreeMap<Self::Key, Selector<Self::Value>>, ) -> Self
where V: Into<Self::Value>, P: Preset<Value = V>,

Create this palette from a preset.

Source

fn with_presets<V, P>( presets: &[P], selectors: BTreeMap<Self::Key, Selector<Self::Value>>, ) -> Self
where V: Into<Self::Value>, P: Preset<Value = V>,

Provided Methods§

Source

fn len(&self) -> usize

The number of values of the (non-override) values.

Source

fn is_empty(&self) -> bool

Whether the values are empty.

Source

fn by_index(&self, index: usize) -> Option<&Self::Value>

Get a value by index. Index undergoes modulo operation such that values are used in a carousel fashion by default.

Source

fn get<K: Into<Self::Key>>(&self, key: K) -> Option<&Self::Value>
where Self::Key: Ord,

Get a value by 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.

Implementors§

Source§

impl<Key: Ord, Color> Container for Palette<Key, Color>

Source§

type Key = Key

Source§

type Value = Color