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:
Lars Volkheimer 2024-02-13 18:51:05 +01:00 committed by GitHub
parent 99b0badcb2
commit 79afcde7d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 2 deletions

View file

@ -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. It is only available when compiling with `--cfg enterprise_license` and obtaining an enterprise license.
For license inquiries, send mail to `/dev/null`. 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 ## MSRV
The minimum supported Rust version of this crate is 1.1000.0. The minimum supported Rust version of this crate is 1.1000.0.

22
src/boolean_toggler.rs Normal file
View 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 }
}
}

View file

@ -1,6 +1,10 @@
#![doc = include_str!("../README.md")] #![doc = include_str!("../README.md")]
#![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(docsrs, feature(doc_cfg))]
mod boolean_toggler;
use boolean_toggler::BooleanTogglerFactory;
// Extension trait for toggling a bool. // Extension trait for toggling a bool.
pub trait TogglingIsALifestyle { pub trait TogglingIsALifestyle {
/// Toggle the bool. /// Toggle the bool.
@ -17,7 +21,7 @@ pub use TogglingIsALifestyle as IAmTheToggler;
impl TogglingIsALifestyle for bool { impl TogglingIsALifestyle for bool {
fn toggle(&mut self) { fn toggle(&mut self) {
// i am so smart // 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) { fn toggle(&mut self) {
// i am so fast // i am so fast
for b in self { for b in self {
*b ^= true; let mut bool_toggler = BooleanTogglerFactory::create_boolean_toggler(b);
bool_toggler.toggle();
} }
} }
} }