Struct Map

Source
pub struct Map<V> { /* private fields */ }
Expand description

A map with a fixed capacity and usize as keys.

Implementations§

Source§

impl<V: Clone> Map<V>

Source

pub fn with_capacity(cap: usize) -> Self

Make it.

§Panics

May panic if out of memory.

Source

pub fn with_capacity_none(cap: usize) -> Self

Make it and prepare all keys.

This is a more expensive operation that with_capacity, because it has to go through all keys and fill them up with None.

§Panics

May panic if out of memory.

Source

pub fn with_capacity_some(cap: usize, v: V) -> Self

Make it and prepare all keys with some value set.

This is a more expensive operation that with_capacity, because it has to go through all keys and fill them up with Some.

§Panics

May panic if out of memory.

Source

pub const fn capacity(&self) -> usize

Return capacity.

Source§

impl<V: Clone> Map<V>

Source

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

Make an iterator over all items.

§Panics

It may panic in debug mode, if the Map is not initialized.

Source

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

Make a mutable iterator over all items.

For example:

use emap::Map;
let mut m: Map<String> = Map::with_capacity_none(16);
m.insert(0, "Jeff".to_string());
m.insert(1, "Lebowski".to_string());
for (_, v) in m.iter_mut() {
  *v = v.to_lowercase();
}

The keys are not mutable, only the values, for obvious reasons.

§Panics

It may panic in debug mode, if the Map is not initialized.

Source

pub const fn into_iter(&self) -> IntoIter<V>

Make an iterator over all items.

§Panics

It may panic in debug mode, if the Map is not initialized.

Source§

impl<V: Clone> Map<V>

Source

pub const fn keys(&self) -> Keys<V>

Make an iterator over all keys.

§Panics

It may panic in debug mode, if the Map is not initialized.

Source§

impl<V: Clone> Map<V>

Source

pub fn is_empty(&self) -> bool

Is it empty?

Source

pub fn len(&self) -> usize

Return the total number of items inside.

§Panics

It may panic in debug mode, if the Map is not initialized.

Source

pub fn contains_key(&self, k: usize) -> bool

Does the map contain this key?

§Panics

It may panic if you attempt to refer to they key that is outside of the boundary of this map. It will not return None, it will panic. However, in “release” mode it will not panic, but will lead to undefined behavior.

Source

pub fn remove(&mut self, k: usize)

Remove by key.

§Panics

It may panic if you attempt to refer to they key that is outside of the boundary of this map. It will not return None, it will panic. However, in “release” mode it will not panic, but will lead to undefined behavior.

Source

pub fn push(&mut self, v: V) -> usize

Push to the rightmost position and return the key.

Source

pub fn insert(&mut self, k: usize, v: V)

Insert a single pair into the map.

§Panics

It may panic if you attempt to refer to they key that is outside of the boundary of this map. It will not return None, it will panic. However, in “release” mode it will not panic, but will lead to undefined behavior.

Source

pub fn get(&self, k: usize) -> Option<&V>

Get a reference to a single value.

§Panics

It may panic if you attempt to refer to they key that is outside of the boundary of this map. It will not return None, it will panic. However, in “release” mode it will not panic, but will lead to undefined behavior.

Source

pub fn get_mut(&mut self, k: usize) -> Option<&mut V>

Get a mutable reference to a single value.

§Panics

It may panic if you attempt to refer to they key that is outside of the boundary of this map. It will not return None, it will panic. However, in “release” mode it will not panic, but will lead to undefined behavior.

Source

pub fn clear(&mut self)

Remove all items from it, but keep the space intact for future use.

Source

pub fn retain<F: Fn(&usize, &V) -> bool>(&mut self, f: F)

Retains only the elements specified by the predicate.

§Panics

It may panic in debug mode, if the Map is not initialized.

Source§

impl<V: Clone> Map<V>

Source

pub fn next_key(&self) -> usize

Get the next key available for insertion.

§Panics

If no more keys left.

Source

pub fn next_key_gte(&self, k: usize) -> usize

Get the next key available for insertion, which is “greater or equal” than the number provided.

§Panics

If no more keys left.

It may also panic in “debug” mode if the Map is not initialized.

Source§

impl<V: Clone> Map<V>

Source

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

Make an iterator over all values.

§Panics

It may panic in debug mode, if the Map is not initialized.

Source

pub const fn into_values(&self) -> IntoValues<V>

Make an into-iterator over all items.

§Panics

It may panic in debug mode, if the Map is not initialized.

Trait Implementations§

Source§

impl<V: Clone> Clone for Map<V>

Source§

fn clone(&self) -> Self

Returns a copy 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<V: Clone + Display> Debug for Map<V>

Source§

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

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

impl<V: Clone + Display> Display for Map<V>

Source§

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

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

impl<V> Drop for Map<V>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<V: Clone> Index<usize> for Map<V>

Source§

type Output = V

The returned type after indexing.
Source§

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

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

impl<V: Clone> IndexMut<usize> for Map<V>

Source§

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

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

impl<'a, V: Copy> IntoIterator for &'a Map<V>

Source§

type Item = (usize, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<V>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<V> Freeze for Map<V>

§

impl<V> RefUnwindSafe for Map<V>
where V: RefUnwindSafe,

§

impl<V> !Send for Map<V>

§

impl<V> !Sync for Map<V>

§

impl<V> Unpin for Map<V>

§

impl<V> UnwindSafe for Map<V>
where V: RefUnwindSafe,

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> 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.