pub struct TagIndex { /* private fields */ }Implementations§
Source§impl TagIndex
impl TagIndex
Sourcepub fn add(&mut self, tag: TeloidTag, id: TeloidID)
pub fn add(&mut self, tag: TeloidTag, id: TeloidID)
Adds a TeloidID to the index for a given TeloidTag.
If the tag does not exist in the index, it will be added. If the ID already exists for the given tag, it will not be added again.
§Arguments
tag- TheTeloidTagto associate with the ID.id- TheTeloidIDto add.
§Examples
use deep_causality_ethos::{TagIndex, TeloidTag, TeloidID};
let mut tag_index = TagIndex::new();
let tag = "test_tag";
let id = 1;
tag_index.add(tag, id);
tag_index.add(tag, id); // Duplicates are ignored
assert_eq!(tag_index.get(tag).unwrap().len(), 1);Sourcepub fn get(&self, tag: &str) -> Option<&HashSet<TeloidID>>
pub fn get(&self, tag: &str) -> Option<&HashSet<TeloidID>>
Retrieves a reference to the set of TeloidIDs associated with a given TeloidTag.
§Arguments
tag- TheTeloidTagto look up.
§Returns
An Option containing a reference to the HashSet of TeloidIDs if the tag exists,
otherwise None.
§Examples
use deep_causality_ethos::{TagIndex, TeloidTag, TeloidID};
use std::collections::HashSet;
let mut tag_index = TagIndex::new();
let tag = "test_tag";
let id = 1;
tag_index.add(tag, id);
let mut expected = HashSet::new();
expected.insert(1);
let ids = tag_index.get(tag);
assert_eq!(ids, Some(&expected));Sourcepub fn remove(&mut self, tag: &str, id: TeloidID)
pub fn remove(&mut self, tag: &str, id: TeloidID)
Removes a TeloidID from the index for a given TeloidTag.
If the tag or ID does not exist, the index remains unchanged.
§Arguments
tag- TheTeloidTagfrom which to remove the ID.id- TheTeloidIDto remove.
§Examples
use deep_causality_ethos::{TagIndex, TeloidTag, TeloidID};
let mut tag_index = TagIndex::new();
let tag = "test_tag";
let id = 1;
tag_index.add(tag, id);
tag_index.remove(tag, id);
assert!(tag_index.get(tag).is_none() || tag_index.get(tag).unwrap().is_empty());Sourcepub fn update(&mut self, tag: &str, id: TeloidID)
pub fn update(&mut self, tag: &str, id: TeloidID)
Adds a TeloidID to an existing entry for a given TeloidTag.
This is similar to add, but it will not create a new entry if the tag doesn’t exist.
§Arguments
tag- TheTeloidTagto update.id- TheTeloidIDto add.
§Examples
use deep_causality_ethos::{TagIndex, TeloidTag, TeloidID};
let mut tag_index = TagIndex::new();
let tag = "test_tag";
let id1 = 1;
let id2 = 2;
tag_index.add(tag, id1);
tag_index.update(tag, id2);
assert_eq!(tag_index.get(tag).unwrap().len(), 2);Sourcepub fn contains_key(&self, tag: &str) -> bool
pub fn contains_key(&self, tag: &str) -> bool
Checks if a TeloidTag exists in the index.
§Arguments
tag- TheTeloidTagto check.
§Returns
true if the tag exists, otherwise false.
§Examples
use deep_causality_ethos::{TagIndex, TeloidTag, TeloidID};
let mut tag_index = TagIndex::new();
let tag = "test_tag";
tag_index.add(tag, 1);
assert!(tag_index.contains_key(tag));Trait Implementations§
impl Eq for TagIndex
impl StructuralPartialEq for TagIndex
Auto Trait Implementations§
impl Freeze for TagIndex
impl RefUnwindSafe for TagIndex
impl Send for TagIndex
impl Sync for TagIndex
impl Unpin for TagIndex
impl UnwindSafe for TagIndex
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