oofs/
tags.rs

1use std::{any::TypeId, collections::HashSet};
2
3#[derive(Debug, Clone)]
4pub struct Tags {
5    set: HashSet<TypeId>,
6}
7
8impl Tags {
9    pub fn new() -> Self {
10        Tags {
11            set: HashSet::new(),
12        }
13    }
14
15    pub fn tag<T: 'static>(&mut self) {
16        self.set.insert(TypeId::of::<T>());
17    }
18
19    pub fn untag<T: 'static>(&mut self) {
20        self.set.remove(&TypeId::of::<T>());
21    }
22
23    pub fn tagged<T: 'static>(&self) -> bool {
24        self.set.contains(&TypeId::of::<T>())
25    }
26
27    pub fn iter(&self) -> impl Iterator<Item = &TypeId> {
28        self.set.iter()
29    }
30}