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)
   }
}
