the crate

This commit is contained in:
nora 2024-02-08 18:13:45 +01:00
commit a379bbc1c3
5 changed files with 97 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "bool-toggle"
version = "1.0.0"

8
Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "bool-toggle"
version = "1.0.0"
edition = "2021"
[package.metadata.docs.rs]
# enable unstable features in the documentation
rustdoc-args = ["--cfg", "docsrs"]

29
README.md Normal file
View file

@ -0,0 +1,29 @@
**i love toggling bools it's one of my favourite things to do**
Provides `fn toggle(&mut self)` on `bool` for toggling bools.
```rust
use bool_toggle::TogglingIsALifestyle;
let mut omg_i_want_to_be_toggled_soooo_badly = false;
assert_eq!(omg_i_want_to_be_toggled_soooo_badly, false);
omg_i_want_to_be_toggled_soooo_badly.toggle();
assert_eq!(omg_i_want_to_be_toggled_soooo_badly, true);
omg_i_want_to_be_toggled_soooo_badly.toggle();
assert_eq!(omg_i_want_to_be_toggled_soooo_badly, false);
```
```rust
let i_dont_want_to_be_toggled = false;
// That's okay.
```
## Enterprise license
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`.
## MSRV
The minimum supported Rust version of this crate is 1.1000.0.
Lower versions might compile but are not supported.

52
src/lib.rs Normal file
View file

@ -0,0 +1,52 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(docsrs, feature(doc_cfg))]
// Extension trait for toggling a bool.
pub trait TogglingIsALifestyle {
/// Toggle the bool.
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) {
// i am so smart
*self ^= true;
}
}
#[cfg(test)]
mod tests {
// cheap 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))]
mod enteprise_tests {
// enterprise-grade tests
// only ran when using an enterprise license for the bool-toggle crate
use super::BoolToggleExt;
#[test]
fn enterprise_toggle() {
let mut b = false;
b.toggle();
assert_eq!(b, true);
}
}