Struct hirofa_utils::auto_id_map::AutoIdMap

source ·
pub struct AutoIdMap<T> {
    pub map: HashMap<usize, T>,
    /* private fields */
}
Expand description

AutoIdMap is a wrapper around HashMap which automatically creates a unique id for it’s entries

§Example


use hirofa_utils::auto_id_map::AutoIdMap;
let mut map = AutoIdMap::new();
let id1 = map.insert("hi");
let id2 = map.insert("hi2");
assert_ne!(id1, id2);
assert_eq!(map.len(), 2);
let s1 = map.remove(&id1);
assert_eq!(s1, "hi");
assert_eq!(map.len(), 1);

Fields§

§map: HashMap<usize, T>

Implementations§

source§

impl<T> AutoIdMap<T>

source

pub fn new() -> AutoIdMap<T>

create a new instance of the AutoIdMap

source

pub fn new_with_max_size(max_size: usize) -> AutoIdMap<T>

source

pub fn foreach_value<F: Fn(&T)>(&self, f: F)

source

pub fn foreach_value_mut<F: Fn(&mut T)>(&mut self, f: F)

source

pub fn foreach<F: Fn(&usize, &T)>(&self, f: F)

source

pub fn clear(&mut self)

source

pub fn remove_values<F: Fn(&T) -> bool>(&mut self, f: F) -> Vec<T>

source

pub fn contains_value<F: Fn(&T) -> bool>(&self, f: F) -> bool

source

pub fn insert(&mut self, elem: T) -> usize

insert an element and return the new id

source

pub fn try_insert(&mut self, elem: T) -> Result<usize, &str>

insert an element and return the new id

source

pub fn replace(&mut self, id: &usize, elem: T)

replace an element, this will panic if you pass an id that is not present

source

pub fn get(&self, id: &usize) -> Option<&T>

get an element based on it’s id

source

pub fn get_mut(&mut self, id: &usize) -> Option<&mut T>

get an element based on it’s id

source

pub fn remove(&mut self, id: &usize) -> T

remove an element based on its id

source

pub fn remove_opt(&mut self, id: &usize) -> Option<T>

remove an element based on its id

source

pub fn len(&self) -> usize

get the size of the map

source

pub fn is_empty(&self) -> bool

see if map is empty

source

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

check if a map contains a certain id

Trait Implementations§

source§

impl<T> Default for AutoIdMap<T>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> Freeze for AutoIdMap<T>

§

impl<T> RefUnwindSafe for AutoIdMap<T>
where T: RefUnwindSafe,

§

impl<T> Send for AutoIdMap<T>
where T: Send,

§

impl<T> Sync for AutoIdMap<T>
where T: Sync,

§

impl<T> Unpin for AutoIdMap<T>
where T: Unpin,

§

impl<T> UnwindSafe for AutoIdMap<T>
where T: 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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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