negative-type-bound 0.1.0

provides negative type bound
Documentation
  • Coverage
  • 33.33%
    1 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 5.13 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.06 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • djdisodo/negative-type-bound
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • djdisodo

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