negative-type-bound

Crates.ionegative-type-bound
lib.rsnegative-type-bound
version0.1.0
sourcesrc
created_at2022-01-10 06:03:39.236177
updated_at2022-01-10 06:03:39.236177
descriptionprovides negative type bound
homepage
repositoryhttps://github.com/djdisodo/negative-type-bound
max_upload_size
id511176
size5,443
sodo (djdisodo)

documentation

README

crates.io

this crate uses feature negative_impls and auto_traits

You may want to do something like

struct Foo<T>(T);

impl<T: From<U>, U> From<Foo<U>> for Foo<T> {
    fn from(v: Foo<U>) -> Self {
        Self(T::from(v.0))
    }
}

but it wont work because it conflicts with implementation impl<T> From<T> for T {} provided by core.

so we have to bound Foo<T> != Foo<U>

this crate provides trait NotEqual

(T, U): NotEqual is equivalent to T != U

so this will work

struct Foo<T>(T);

impl<T: From<U>, U> From<Foo<U>> for Foo<T> where (Foo<T>, Foo<U>): NotEqual {
    fn from(v: Foo<U>) -> Self {
        Self(T::from(v.0))
    }
}

more simply...

struct Foo<T>(T);

impl<T: From<U>, U> From<Foo<U>> for Foo<T> where (T, U): NotEqual {
    fn from(v: Foo<U>) -> Self {
        Self(T::from(v.0))
    }
}

this crate also provides Equal

Commit count: 1

cargo fmt