Type Alias Entitys

Source
pub type Entitys = DenseSlotMap<EntityKey, Entity>;

Aliased Type§

pub struct Entitys { /* private fields */ }

Implementations

Source§

impl<K, V> DenseSlotMap<K, V>
where K: Key,

Source

pub fn with_key() -> DenseSlotMap<K, V>

Constructs a new, empty DenseSlotMap with a custom key type.

§Examples
new_key_type! {
    struct PositionKey;
}
let mut positions: DenseSlotMap<PositionKey, i32> = DenseSlotMap::with_key();
Source

pub fn with_capacity_and_key(capacity: usize) -> DenseSlotMap<K, V>

Creates an empty DenseSlotMap with the given capacity and a custom key type.

The slot map will not reallocate until it holds at least capacity elements.

§Examples
new_key_type! {
    struct MessageKey;
}
let mut messages = DenseSlotMap::with_capacity_and_key(3);
let welcome: MessageKey = messages.insert("Welcome");
let good_day = messages.insert("Good day");
let hello = messages.insert("Hello");
Source

pub fn len(&self) -> usize

Returns the number of elements in the slot map.

§Examples
let mut sm = DenseSlotMap::with_capacity(10);
sm.insert("len() counts actual elements, not capacity");
let key = sm.insert("removed elements don't count either");
sm.remove(key);
assert_eq!(sm.len(), 1);
Source

pub fn is_empty(&self) -> bool

Returns if the slot map is empty.

§Examples
let mut sm = DenseSlotMap::new();
let key = sm.insert("dummy");
assert_eq!(sm.is_empty(), false);
sm.remove(key);
assert_eq!(sm.is_empty(), true);
Source

pub fn capacity(&self) -> usize

Returns the number of elements the DenseSlotMap can hold without reallocating.

§Examples
let sm: DenseSlotMap<_, f64> = DenseSlotMap::with_capacity(10);
assert_eq!(sm.capacity(), 10);
Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more elements to be inserted in the DenseSlotMap. The collection may reserve more space to avoid frequent reallocations.

§Panics

Panics if the new allocation size overflows usize.

§Examples
let mut sm = DenseSlotMap::new();
sm.insert("foo");
sm.reserve(32);
assert!(sm.capacity() >= 33);
Source

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

Returns true if the slot map contains key.

§Examples
let mut sm = DenseSlotMap::new();
let key = sm.insert(42);
assert_eq!(sm.contains_key(key), true);
sm.remove(key);
assert_eq!(sm.contains_key(key), false);
Source

pub fn insert(&mut self, value: V) -> K

Inserts a value into the slot map. Returns a unique key that can be used to access this value.

§Panics

Panics if the number of elements in the slot map equals 232 - 2.

§Examples
let mut sm = DenseSlotMap::new();
let key = sm.insert(42);
assert_eq!(sm[key], 42);
Source

pub fn insert_with_key<F>(&mut self, f: F) -> K
where F: FnOnce(K) -> V,

Inserts a value given by f into the slot map. The key where the value will be stored is passed into f. This is useful to store values that contain their own key.

§Panics

Panics if the number of elements in the slot map equals 232 - 2.

§Examples
let mut sm = DenseSlotMap::new();
let key = sm.insert_with_key(|k| (k, 20));
assert_eq!(sm[key], (key, 20));
Source

pub fn remove(&mut self, key: K) -> Option<V>

Removes a key from the slot map, returning the value at the key if the key was not previously removed.

§Examples
let mut sm = DenseSlotMap::new();
let key = sm.insert(42);
assert_eq!(sm.remove(key), Some(42));
assert_eq!(sm.remove(key), None);
Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(K, &mut V) -> bool,

Retains only the elements specified by the predicate.

In other words, remove all key-value pairs (k, v) such that f(k, &mut v) returns false. This method invalidates any removed keys.

§Examples
let mut sm = DenseSlotMap::new();

let k3 = sm.insert(2);
let k1 = sm.insert(0);
let k2 = sm.insert(1);

sm.retain(|key, val| key == k1 || *val == 1);

assert!(sm.contains_key(k1));
assert!(sm.contains_key(k2));
assert!(!sm.contains_key(k3));

assert_eq!(2, sm.len());
Source

pub fn clear(&mut self)

Clears the slot map. Keeps the allocated memory for reuse.

§Examples
let mut sm = DenseSlotMap::new();
for i in 0..10 {
    sm.insert(i);
}
assert_eq!(sm.len(), 10);
sm.clear();
assert_eq!(sm.len(), 0);
Source

pub fn drain(&mut self) -> Drain<'_, K, V>

Clears the slot map, returning all key-value pairs in arbitrary order as an iterator. Keeps the allocated memory for reuse.

§Examples
let mut sm = DenseSlotMap::new();
let k = sm.insert(0);
let v: Vec<_> = sm.drain().collect();
assert_eq!(sm.len(), 0);
assert_eq!(v, vec![(k, 0)]);
Source

pub fn get(&self, key: K) -> Option<&V>

Returns a reference to the value corresponding to the key.

§Examples
let mut sm = DenseSlotMap::new();
let key = sm.insert("bar");
assert_eq!(sm.get(key), Some(&"bar"));
sm.remove(key);
assert_eq!(sm.get(key), None);
Source

pub unsafe fn get_unchecked(&self, key: K) -> &V

Returns a reference to the value corresponding to the key without version or bounds checking.

§Safety

This should only be used if contains_key(key) is true. Otherwise it is potentially unsafe.

§Examples
let mut sm = DenseSlotMap::new();
let key = sm.insert("bar");
assert_eq!(unsafe { sm.get_unchecked(key) }, &"bar");
sm.remove(key);
// sm.get_unchecked(key) is now dangerous!
Source

pub fn get_mut(&mut self, key: K) -> Option<&mut V>

Returns a mutable reference to the value corresponding to the key.

§Examples
let mut sm = DenseSlotMap::new();
let key = sm.insert(3.5);
if let Some(x) = sm.get_mut(key) {
    *x += 3.0;
}
assert_eq!(sm[key], 6.5);
Source

pub unsafe fn get_unchecked_mut(&mut self, key: K) -> &mut V

Returns a mutable reference to the value corresponding to the key without version or bounds checking.

§Safety

This should only be used if contains_key(key) is true. Otherwise it is potentially unsafe.

§Examples
let mut sm = DenseSlotMap::new();
let key = sm.insert("foo");
unsafe { *sm.get_unchecked_mut(key) = "bar" };
assert_eq!(sm[key], "bar");
sm.remove(key);
// sm.get_unchecked_mut(key) is now dangerous!
Source

pub fn iter(&self) -> Iter<'_, K, V>

An iterator visiting all key-value pairs in arbitrary order. The iterator element type is (K, &'a V).

§Examples
let mut sm = DenseSlotMap::new();
let k0 = sm.insert(0);
let k1 = sm.insert(1);
let k2 = sm.insert(2);

let mut it = sm.iter();
for (k, v) in sm.iter() {
    println!("key: {:?}, val: {}", k, v);
}
Source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

An iterator visiting all key-value pairs in arbitrary order, with mutable references to the values. The iterator element type is (K, &'a mut V).

§Examples
let mut sm = DenseSlotMap::new();
let k0 = sm.insert(10);
let k1 = sm.insert(20);
let k2 = sm.insert(30);

for (k, v) in sm.iter_mut() {
    if k != k1 {
        *v *= -1;
    }
}

assert_eq!(sm[k0], -10);
assert_eq!(sm[k1], 20);
assert_eq!(sm[k2], -30);
Source

pub fn keys(&self) -> Keys<'_, K, V>

An iterator visiting all keys in arbitrary order. The iterator element type is K.

§Examples
let mut sm = DenseSlotMap::new();
let k0 = sm.insert(10);
let k1 = sm.insert(20);
let k2 = sm.insert(30);
let keys: HashSet<_> = sm.keys().collect();
let check: HashSet<_> = vec![k0, k1, k2].into_iter().collect();
assert_eq!(keys, check);
Source

pub fn values(&self) -> Values<'_, K, V>

An iterator visiting all values in arbitrary order. The iterator element type is &'a V.

§Examples
let mut sm = DenseSlotMap::new();
let k0 = sm.insert(10);
let k1 = sm.insert(20);
let k2 = sm.insert(30);
let values: HashSet<_> = sm.values().collect();
let check: HashSet<_> = vec![&10, &20, &30].into_iter().collect();
assert_eq!(values, check);
Source

pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>

An iterator visiting all values mutably in arbitrary order. The iterator element type is &'a mut V.

§Examples
let mut sm = DenseSlotMap::new();
sm.insert(1);
sm.insert(2);
sm.insert(3);
sm.values_mut().for_each(|n| { *n *= 3 });
let values: HashSet<_> = sm.into_iter().map(|(_k, v)| v).collect();
let check: HashSet<_> = vec![3, 6, 9].into_iter().collect();
assert_eq!(values, check);

Trait Implementations

Source§

impl<K, V> Clone for DenseSlotMap<K, V>
where K: Clone + Key, V: Clone,

Source§

fn clone(&self) -> DenseSlotMap<K, V>

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<K, V> Debug for DenseSlotMap<K, V>
where K: Debug + Key, V: Debug,

Source§

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

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

impl<K, V> Default for DenseSlotMap<K, V>
where K: Key,

Source§

fn default() -> DenseSlotMap<K, V>

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

impl<K, V> Index<K> for DenseSlotMap<K, V>
where K: Key,

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, key: K) -> &V

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

impl<K, V> IndexMut<K> for DenseSlotMap<K, V>
where K: Key,

Source§

fn index_mut(&mut self, key: K) -> &mut V

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

impl<K, V> IntoIterator for DenseSlotMap<K, V>
where K: Key,

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <DenseSlotMap<K, V> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more