#![doc = include_str!("../README.md")]
#![cfg_attr(docsrs, feature(doc_cfg))]
pub trait TogglingIsALifestyle {
fn toggle(&mut self);
}
#[cfg_attr(not(docsrs), cfg(enterprise_license))]
#[cfg_attr(docsrs, doc(cfg(enterprise_license)))]
pub use TogglingIsALifestyle as BoolToggleExt;
pub use TogglingIsALifestyle as Toggler;
pub use TogglingIsALifestyle as Toggling;
pub use TogglingIsALifestyle as IAmTheToggler;
impl TogglingIsALifestyle for bool {
fn toggle(&mut self) {
*self ^= true;
}
}
#[cfg(enterprise_license)]
impl<const N: usize> TogglingIsALifestyle for [bool; N] {
fn toggle(&mut self) {
for b in self {
*b ^= true;
}
}
}
#[cfg(test)]
#[allow(clippy::bool_assert_comparison)]
mod tests {
use super::TogglingIsALifestyle;
#[test]
fn toggle() {
let mut b = false;
b.toggle();
assert_eq!(b, true);
b.toggle();
assert_eq!(b, false);
}
}
#[cfg(all(test, enterprise_license))]
#[allow(clippy::bool_assert_comparison)]
mod enteprise_tests {
use super::BoolToggleExt;
#[test]
fn enterprise_toggle() {
let mut b = false;
b.toggle();
assert_eq!(b, true);
}
#[test]
fn enterprise_simd_toggle() {
let mut b = [false, true, false];
b.toggle();
assert_eq!(b, [true, false, true]);
}
}