approxeq 0.1.1

A trait for approximate equality of types
Documentation
  • Coverage
  • 25%
    1 out of 4 items documented1 out of 3 items with examples
  • Size
  • Source code size: 9.64 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.41 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
  • old-mibmo/approxeq
    0 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mibmo

ApproxEq

Crate Documentation Current Crates.io Version

The ApproxEq trait handily provides a way to define approximate relations between types and comes with already-declared arbitrary implementations for primitive number types!

Easily define implementations for your own types:

use approxeq::ApproxEq;

enum BookFormat {
    Paperback,
    Hardback,
    Ebook,
}

struct Book {
    isbn: i32,
    format: BookFormat,
}

impl ApproxEq for Book {
    // Two books are approximately equal when their respective ISBNs parity matches
    fn aeq(&self, &other: Self) -> bool {
        self.isbn % 2 == other.isbn %2
    }
}

fn main() {
    let b1 = Book { isbn: 3, format: Paperback }
    let b2 = Book { isbn: 5, format: Hardback }
    let b3 = Book { isbn: 10, format: Ebook }

    assert!(b1.aeq(&b2));
    assert!(b1.nae(&b3));
}

Contributing

Any and all PRs are welcome.

Acknowledgement

The ApproxEq crate is what you might call a joke.

Much of the documentation is an adaptation of rust-lang's std::cmp::PartialEq trait documentation.