Repository: bitflags/bitflags (Rust)

Issue:
No `clear()` method?
~~The previous major version used to have a `clear` method (i think?), while migrating to the new version i saw that this method was not present anymore, is this expected? it feels like a common behaviour to include, currently i'm doing this~~
I used to clear the flags by doing `self.bits = 0` in the old version of the library, in the current major version i saw this seems to be a way to do it instead, is there a reason why there is not a `.clear()` method or similar that unsets all bits?
```rust
bitflags! {
    #[wasm_bindgen]
    #[derive(Serialize, Copy, Clone, Debug)]
    pub struct Flags: u16 {
        const Carry    = 1<<1;
        const Overflow = 1<<2;
        const Zero     = 1<<3;
        const Negative = 1<<4;
        const Extend   = 1<<5;
    }
}

impl Flags {
    pub fn clear(&mut self) {
        self.set(Flags::all(), false);
        //or
       *self = Flags::empty();
    }
}
```


Discussion:
Hi @Specy 👋

There’s no particular reason we can’t have a `clear()` method. We already have other mutating methods on generated flags types. We can add it to the `Flags` trait freely, but can’t introduce it as an inherent method on generated flags types without potentially breaking user code.

Without the inherent method, I think the `self = Flags::empty()` option is probably the best.
Considering a function like this doesn't seem to have been requested a lot in the past, I guess the use case is not very sought after either 
For what it's worth, it's definitely a use case that has applied to me in the past. I can go ahead and make a PR to add this function if desired.
Adding a `Flags::clear(&mut self) { *self = Self::empty(); }` method would be a reasonable change I think :+1:



Patch:
diff --git a/src/traits.rs b/src/traits.rs
index d351bfce..d7c4d13b 100644
--- a/src/traits.rs
+++ b/src/traits.rs
@@ -293,6 +293,14 @@ pub trait Flags: Sized + 'static {
         }
     }
 
+    /// Unsets all bits in the flags.
+    fn clear(&mut self)
+    where
+        Self: Sized,
+    {
+        *self = Self::empty();
+    }
+
     /// The bitwise and (`&`) of the bits in two flags values.
     #[must_use]
     fn intersection(self, other: Self) -> Self {


Test patch:
diff --git a/src/tests.rs b/src/tests.rs
index 547c28d7..0770e1b3 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -1,6 +1,7 @@
 mod all;
 mod bitflags_match;
 mod bits;
+mod clear;
 mod complement;
 mod contains;
 mod difference;
diff --git a/src/tests/clear.rs b/src/tests/clear.rs
new file mode 100644
index 00000000..2d42cce4
--- /dev/null
+++ b/src/tests/clear.rs
@@ -0,0 +1,27 @@
+use super::*;
+
+use crate::Flags;
+
+#[test]
+fn cases() {
+    case(TestFlags::from_bits_retain(0));
+
+    case(TestFlags::from_bits_retain(1 << 3));
+
+    case(TestFlags::ABC | TestFlags::from_bits_retain(1 << 3));
+
+    case(TestZero::empty());
+
+    case(TestZero::all());
+
+    case(TestFlags::from_bits_retain(1 << 3) | TestFlags::all());
+}
+
+#[track_caller]
+fn case<T: Flags + std::fmt::Debug>(mut flags: T)
+where
+    T: std::fmt::Debug + PartialEq + Copy,
+{
+    flags.clear();
+    assert_eq!(flags, T::empty(), "{:?}.clear()", flags);
+}