diff --git a/library/core/src/option.rs b/library/core/src/option.rs index e3c4758bc6af5..aa6ffaff5b85e 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1842,6 +1842,20 @@ impl Option { mem::replace(self, None) } + /// Clear the value of the option. + /// + /// # Examples + /// + /// ``` + /// let mut x = Some(2); + /// x.clear(); + /// assert_eq!(x, None); + /// ``` + #[inline(always)] + pub fn clear(&mut self) { + *self = None; + } + /// Takes the value out of the option, but only if the predicate evaluates to /// `true` on a mutable reference to the value. ///