type-equals

crates.io crates.io docs.rs GitHub

A trait for checking type equality.

This crate implements the TypeEquals trick described in rust-lang/rust#20041.

The following compiles:

```rust use type_equals::TypeEquals;

pub trait Owner { type Child1: Child; type Child2: Child; }

pub trait Child { type Owner: Owner; }

pub struct A; impl Owner for A { type Child1 = B; type Child2 = C; }

pub struct B; impl Child for B { type Owner = A; }

pub struct C; impl Child for C { type Owner = A; }

pub fn wantchildone() where ::Child1: TypeEquals, {}

pub fn wantchildtwo() where ::Child2: TypeEquals, {}

pub fn thisworks() { wantchildone::(); wantchild_two::(); } ```

Meanwhile, the following does not compile: ```rust // A, B, C, wantchildone and wantchildtwo are declared identically.

pub fn thisdoesnotwork() { wantchildone::(); wantchild_two::(); } ```