| Crates.io | hashmapbool |
| lib.rs | hashmapbool |
| version | 0.1.1 |
| created_at | 2025-06-20 03:40:29.819525+00 |
| updated_at | 2025-06-20 03:59:48.729854+00 |
| description | The new and improved way to use boolean values in your rust code, requiring heap allocation and wasting resources on conversion. |
| homepage | https://github.com/wait-what/hashmapbool |
| repository | https://github.com/wait-what/hashmapbool |
| max_upload_size | |
| id | 1719090 |
| size | 6,504 |
The new and improved way to use boolean values in your rust code, requiring heap allocation and wasting resources on conversion.
I wonder if LLVM would optimize it out of existence...
pub struct HashMapBool {
map: HashMap<(), ()>,
}
The value depends on whether or not the HashMap contains a value. If it contains a value, it's true, otherwise it's false.
Due to the use of std::collections::HashMap, std is required.
let a: HashMapBool = true.into();
let b: HashMapBool = false.into();
assert_eq!(a, true);
assert_eq!(b, false);
assert!(a.is_true());
assert!(b.is_false());
// into() moves the value out of the HashMapBool
// so we need to clone it to read the value without consuming it
if a.clone().into() && b.into() {
unreachable!();
}
let mut c = HashMapBool::new(false);
assert!(c.is_false());
c.set_true().unwrap();
assert!(c.is_true());
assert_eq!(a, c);
assert_eq!(a.is_true(), c.get_value());
let d = !c.clone(); // c would be moved without clone
assert!(c.is_true());
assert!(d.is_false());
MIT