Files
tavernworks/bard/src/togglable.rs
Myrddin Dundragon 8f61185434 Adding and moving a lot of components.
This is the main thrust of the library. I know it is a lot of changes,
but I was running out of time and had to hammer them all in.
2025-09-24 19:50:38 -04:00

38 lines
574 B
Rust

use std::collections::HashSet;
/// Trait to toggle the presence of a value (like a tag) in a set.
pub trait Togglable
{
type Item: ?Sized;
fn toggle(&mut self, item: &Self::Item);
fn is_toggled(&self, item: &Self::Item) -> bool;
}
impl Togglable for HashSet<String>
{
type Item = str;
fn toggle(&mut self, item: &str)
{
if self.contains(item)
{
self.remove(item);
}
else
{
self.insert(item.to_owned());
}
}
fn is_toggled(&self, item: &str) -> bool
{
self.contains(item)
}
}