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.
This commit is contained in:
37
bard/src/togglable.rs
Normal file
37
bard/src/togglable.rs
Normal file
@ -0,0 +1,37 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user