diff --git a/src/virtual_dom/mod.rs b/src/virtual_dom/mod.rs index 9ba19f2a03c..4859f1d1c0e 100644 --- a/src/virtual_dom/mod.rs +++ b/src/virtual_dom/mod.rs @@ -41,7 +41,7 @@ type Listeners = Vec>>; type Attributes = HashMap; /// A set of classes. -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Classes { set: IndexSet, } @@ -55,6 +55,8 @@ impl Classes { } /// Adds a class to a set. + /// + /// Prevents duplication of class names. pub fn push(&mut self, class: &str) { self.set.insert(class.into()); } @@ -63,6 +65,14 @@ impl Classes { pub fn contains(&self, class: &str) -> bool { self.set.contains(class) } + + /// Adds other classes to this set of classes; returning itself. + /// + /// Takes the logical union of both `Classes`. + pub fn extend>(mut self, other: T) -> Self { + self.set.extend(other.into().set.into_iter()); + self + } } impl ToString for Classes {