Crates.io | negative-type-bound |
lib.rs | negative-type-bound |
version | 0.1.0 |
source | src |
created_at | 2022-01-10 06:03:39.236177 |
updated_at | 2022-01-10 06:03:39.236177 |
description | provides negative type bound |
homepage | |
repository | https://github.com/djdisodo/negative-type-bound |
max_upload_size | |
id | 511176 |
size | 5,443 |
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