diff --git a/src/lib.rs b/src/lib.rs index 3751852..d9680eb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -772,6 +772,35 @@ impl>> RemAssign for FlagSet { } } +impl>> Extend for FlagSet { + /// Add values by iterating over some collection. + /// + /// ``` + /// use flagset::{FlagSet, flags}; + /// + /// flags! { + /// pub enum Flag: u8 { + /// Foo = 1, + /// Bar = 2, + /// Baz = 4 + /// } + /// } + /// + /// let flag_vec = vec![Flag::Bar, Flag::Baz]; + /// let mut some_extended_flags = FlagSet::from(Flag::Foo); + /// some_extended_flags.extend(flag_vec); + /// assert_eq!(some_extended_flags, Flag::Foo | Flag::Bar | Flag::Baz); + /// ``` + fn extend(&mut self, iter: T) + where + T: IntoIterator, + { + for item in iter { + *self |= item; + } + } +} + impl FlagSet { /// Creates a new set from bits; returning `Err(InvalidBits)` on invalid/unknown bits. ///