malachite_base/bools/not_assign.rs
1// Copyright © 2025 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9use crate::num::logic::traits::NotAssign;
10
11impl NotAssign for bool {
12 /// Replaces a [`bool`] by its opposite.
13 ///
14 /// $b \gets \lnot b$.
15 ///
16 /// # Worst-case complexity
17 /// Constant time and additional memory.
18 ///
19 /// # Examples
20 /// ```
21 /// use malachite_base::num::logic::traits::NotAssign;
22 ///
23 /// let mut b = false;
24 /// b.not_assign();
25 /// assert_eq!(b, true);
26 ///
27 /// let mut b = true;
28 /// b.not_assign();
29 /// assert_eq!(b, false);
30 /// ```
31 #[inline]
32 fn not_assign(&mut self) {
33 *self = !*self;
34 }
35}