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>
impl<T> AutoIdMap<T>
pub fn new_with_max_size(max_size: usize) -> AutoIdMap<T>
pub fn foreach_value<F: Fn(&T)>(&self, f: F)
pub fn foreach_value_mut<F: Fn(&mut T)>(&mut self, f: F)
pub fn foreach<F: Fn(&usize, &T)>(&self, f: F)
pub fn clear(&mut self)
pub fn remove_values<F: Fn(&T) -> bool>(&mut self, f: F) -> Vec<T>
pub fn contains_value<F: Fn(&T) -> bool>(&self, f: F) -> bool
sourcepub fn try_insert(&mut self, elem: T) -> Result<usize, &str>
pub fn try_insert(&mut self, elem: T) -> Result<usize, &str>
insert an element and return the new id
sourcepub fn replace(&mut self, id: &usize, elem: T)
pub fn replace(&mut self, id: &usize, elem: T)
replace an element, this will panic if you pass an id that is not present
sourcepub fn remove_opt(&mut self, id: &usize) -> Option<T>
pub fn remove_opt(&mut self, id: &usize) -> Option<T>
remove an element based on its id
sourcepub fn contains_key(&self, id: &usize) -> bool
pub fn contains_key(&self, id: &usize) -> bool
check if a map contains a certain id
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more