mirror of
https://github.com/Noratrieb/bool-toggle.git
synced 2026-01-14 12:25:01 +01:00
IMPROVEMENT better code maintainablity by removing duplicated code (#2)
* feat: adhere to the strictest clean code standards and DRY * docs: document enterprise grade arichitecture * fix: copy pasta * Small improvements * make clippy happy --------- Co-authored-by: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com>
This commit is contained in:
parent
99b0badcb2
commit
79afcde7d5
3 changed files with 34 additions and 2 deletions
|
|
@ -23,6 +23,11 @@ This crate supports a professional re-export of the trait, `BoolToggleExt`.
|
|||
It is only available when compiling with `--cfg enterprise_license` and obtaining an enterprise license.
|
||||
For license inquiries, send mail to `/dev/null`.
|
||||
|
||||
## Architecture
|
||||
|
||||
This Crate features the world's most resilient bit flipping algorithm. Its code adheres to the highest clean code standards
|
||||
and aims to provide a maintainable and future proof solution to all the boolean toggling needs there are.
|
||||
|
||||
## MSRV
|
||||
|
||||
The minimum supported Rust version of this crate is 1.1000.0.
|
||||
|
|
|
|||
22
src/boolean_toggler.rs
Normal file
22
src/boolean_toggler.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use super::TogglingIsALifestyle;
|
||||
|
||||
pub struct BooleanToggler<'a> {
|
||||
bool_to_toggle: &'a mut bool,
|
||||
}
|
||||
|
||||
impl TogglingIsALifestyle for BooleanToggler<'_> {
|
||||
#[inline]
|
||||
fn toggle(&mut self) {
|
||||
// i'm enterprise fast
|
||||
*self.bool_to_toggle ^= true;
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BooleanTogglerFactory;
|
||||
|
||||
impl BooleanTogglerFactory {
|
||||
#[inline]
|
||||
pub fn create_boolean_toggler(bool_to_toggle: &mut bool) -> BooleanToggler {
|
||||
BooleanToggler { bool_to_toggle }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
#![doc = include_str!("../README.md")]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
|
||||
mod boolean_toggler;
|
||||
|
||||
use boolean_toggler::BooleanTogglerFactory;
|
||||
|
||||
// Extension trait for toggling a bool.
|
||||
pub trait TogglingIsALifestyle {
|
||||
/// Toggle the bool.
|
||||
|
|
@ -17,7 +21,7 @@ pub use TogglingIsALifestyle as IAmTheToggler;
|
|||
impl TogglingIsALifestyle for bool {
|
||||
fn toggle(&mut self) {
|
||||
// i am so smart
|
||||
*self ^= true;
|
||||
BooleanTogglerFactory::create_boolean_toggler(self).toggle();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -26,7 +30,8 @@ impl<const N: usize> TogglingIsALifestyle for [bool; N] {
|
|||
fn toggle(&mut self) {
|
||||
// i am so fast
|
||||
for b in self {
|
||||
*b ^= true;
|
||||
let mut bool_toggler = BooleanTogglerFactory::create_boolean_toggler(b);
|
||||
bool_toggler.toggle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue