hashmapbool 0.1.1

The new and improved way to use boolean values in your rust code, requiring heap allocation and wasting resources on conversion.
Documentation
  • Coverage
  • 0%
    0 out of 8 items documented0 out of 7 items with examples
  • Size
  • Source code size: 6.01 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.44 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • wait-what/hashmapbool
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • wait-what

HashMapBool

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...

How it works

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.

Example usage

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());

License

MIT