always_equal 1.0.3

A wrapper for types that can't implement Eq
Documentation
  • Coverage
  • 62.5%
    5 out of 8 items documented3 out of 6 items with examples
  • Size
  • Source code size: 7.06 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.75 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ReactorScram

Always-Equal

Always-Equal lets you wrap PartialEq implementations around things that cannot be compared, like a File.

To use Always-Equal, put these two conditional use statements in your module:

#[cfg (test)]
use always_equal::test::AlwaysEqual;

#[cfg (not (test))]
use always_equal::prod::AlwaysEqual;

Then wrap AlwaysEqual around anything that needs PartialEq but can't possibly implement it:

use std::fs::File;
use always_equal::test::AlwaysEqual;

#[derive (Debug, PartialEq)]
pub struct MyStruct {
	pub b: bool,
	pub i: i64,
	pub file: AlwaysEqual <File>,
}

// In test code, you can create an empty wrapper using
// `testing_blank`, which is equal to any other wrapper:

let expected = MyStruct {
	b: true,
	i: 0,
	file: AlwaysEqual::testing_blank (),
};

# let my_file = File::open ("Cargo.toml").unwrap ();
let actual = MyStruct {
	b: true,
	i: 0,
	file: my_file.into (),
};

assert_eq! (expected, actual);

This is implemented with Option in test mode. In production mode, wrappers are never equal to any other wrapper, and the Option is removed so that sizeof::<AlwaysEqual <T>> () == sizeof::<T> should be true.