KeyedVec

Struct KeyedVec 

Source
pub struct KeyedVec<Key, Value> { /* private fields */ }
Expand description

Structure for storing elements of type Value, the structure can only be indexed by structures of type Key.

Almost all features of this structure require that Key implements the StorageKey trait.

Implementations§

Source§

impl<Key, Value> KeyedVec<Key, Value>
where Key: StorageKey,

Source

pub fn push(&mut self, value: Value) -> Key

Add a new value to the vector.

Returns the key for the inserted value.

Source

pub fn new_slot(&mut self) -> Slot<'_, Key, Value>

Create a new slot for a value, and populate it using Slot::populate().

This allows initializing the value with the ID it will have in this vector.

§Example
#[derive(Clone)]
struct Key(usize);

impl StorageKey for Key {
    // ...
}

struct Value;

/// Create a value based on the specified key.
fn create_value(key: Key) -> Value {
    // ...
}

let mut keyed_vec: KeyedVec<Key, Value> = KeyedVec::default();

// Reserve a slot.
let slot = keyed_vec.new_slot();
// Create the value.
let value = create_value(slot.key());
// Populate the slot.
slot.populate(value);
Source

pub fn iter(&self) -> impl Iterator<Item = &Value>

Iterate over the values in the vector.

Trait Implementations§

Source§

impl<Key, Value> Clone for KeyedVec<Key, Value>
where Value: Clone,

Source§

fn clone(&self) -> KeyedVec<Key, Value>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Key, Value> Debug for KeyedVec<Key, Value>
where Key: Debug, Value: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<Key, Value> Default for KeyedVec<Key, Value>

Source§

fn default() -> KeyedVec<Key, Value>

Returns the “default value” for a type. Read more
Source§

impl<Key, Value> Hash for KeyedVec<Key, Value>
where Key: Hash, Value: Hash,

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<Key, Value> Index<&Key> for KeyedVec<Key, Value>
where Key: StorageKey,

Source§

type Output = Value

The returned type after indexing.
Source§

fn index(&self, index: &Key) -> &<KeyedVec<Key, Value> as Index<&Key>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<Key, Value> Index<Key> for KeyedVec<Key, Value>
where Key: StorageKey,

Source§

type Output = Value

The returned type after indexing.
Source§

fn index(&self, index: Key) -> &<KeyedVec<Key, Value> as Index<Key>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<Key, Value> IndexMut<Key> for KeyedVec<Key, Value>
where Key: StorageKey,

Source§

fn index_mut( &mut self, index: Key, ) -> &mut <KeyedVec<Key, Value> as Index<Key>>::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<Key, Value> PartialEq for KeyedVec<Key, Value>
where Key: PartialEq, Value: PartialEq,

Source§

fn eq(&self, other: &KeyedVec<Key, Value>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Key, Value> Eq for KeyedVec<Key, Value>
where Key: Eq, Value: Eq,

Source§

impl<Key, Value> StructuralPartialEq for KeyedVec<Key, Value>

Auto Trait Implementations§

§

impl<Key, Value> Freeze for KeyedVec<Key, Value>

§

impl<Key, Value> RefUnwindSafe for KeyedVec<Key, Value>
where Key: RefUnwindSafe, Value: RefUnwindSafe,

§

impl<Key, Value> Send for KeyedVec<Key, Value>
where Key: Send, Value: Send,

§

impl<Key, Value> Sync for KeyedVec<Key, Value>
where Key: Sync, Value: Sync,

§

impl<Key, Value> Unpin for KeyedVec<Key, Value>
where Key: Unpin, Value: Unpin,

§

impl<Key, Value> UnwindSafe for KeyedVec<Key, Value>
where Key: UnwindSafe, Value: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<'p, T> Seq<'p, T> for T
where T: Clone,

Source§

type Item<'a> = &'a T where T: 'a

The item yielded by the iterator.
Source§

type Iter<'a> = Once<&'a T> where T: 'a

An iterator over the items within this container, by reference.
Source§

fn seq_iter(&self) -> <T as Seq<'p, T>>::Iter<'_>

Iterate over the elements of the container.
Source§

fn contains(&self, val: &T) -> bool
where T: PartialEq,

Check whether an item is contained within this sequence.
Source§

fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>
where 'p: 'b,

Convert an item of the sequence into a MaybeRef.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> OrderedSeq<'_, T> for T
where T: Clone,