#traits #different #type #enforcing #tuple #pair #non-distinct

nightly distinct

Two traits for enforcing that two types either must be the same or must be different

2 releases

0.1.1 Jun 21, 2020
0.1.0 Jun 21, 2020

#1795 in Rust patterns

MIT/Apache

7KB

distinct

Crates.io Page Docs.rs Page

Two traits for enforcing that two types either must be the same or must be different.

Usage

To use in your crate, add this to your Cargo.toml:

[dependencies]
distinct = "0.1.1"

and add this where you want to use it:

use distinct::{Distinct, NonDistinct};

For full documentation on how to use it, consult this crate's documentation on docs.rs.


lib.rs:

A pair of traits which can be used to ensure that two types either are distinct or are not distinct.

There are two traits: Distinct and NonDistinct. Distinct is implemented for tuples of two distinct types. NonDistinct is implemented for tuples of two of the same type.

Examples

use distinct::{Distinct, NonDistinct};
// Two functions which enforce that the given type is distinct.
fn assert_is_distinct<T: Distinct + ?Sized>() {}
fn assert_is_non_distinct<T: NonDistinct + ?Sized>() {}

assert_is_distinct::<(u32, u64)>();
assert_is_non_distinct::<(u32, u32)>();

No runtime deps