2 个版本
0.1.1 | 2020年6月21日 |
---|---|
0.1.0 | 2020年6月21日 |
#4 在 #enforcing 中
7KB
distinct
两个特质,用于强制两个类型要么相同,要么不同。
使用方法
要在您的包中使用,请将以下内容添加到您的 Cargo.toml
[dependencies]
distinct = "0.1.1"
并将此内容添加到您想使用它的地方
use distinct::{Distinct, NonDistinct};
有关如何使用的完整文档,请参阅此包在 docs.rs 上的文档。
lib.rs
:
一对特质,可以用来确保两个类型要么是不同的,要么不是不同的。
有两个特质:`Distinct` 和 `NonDistinct`。`Distinct` 适用于不同类型的元组。`NonDistinct` 适用于相同类型的元组。
示例
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)>();