'not-equal' type bound, e.g. where T!=Y?


#1

would there be any demand for a ‘not-equal’ constraint that can be added in where clauses,

the situation I ran into was: implementing generic conversions for a collection (a ‘Vec3(T,T,T)’ in my specific case but it could have been anything) , which in turn conflicted with the ‘reflexive implementation of From’ in ‘core’,e.g. T:From<T> conflicts with Vec3<A>:From<Vec3<B>> if B==A

I wondered if this demand would appear in any other situations, justifying a language feature.

here’s the reddit thread,

I had a workable solution for my purposes, but it would have been nicer if this could be made to work; maybe there are other options aswell

maybe this could be fixed without a language feature with some convention around an ‘IsNot’ or something… maybe there would be a way to disable the reflexive ‘From’ if it depended on something that you can disable (‘negative trait bounds???’) for your own types.

// original attempt pub struct Vec3 {pub x:T, pub y:T, pub z:T}
impl<A,B> From<Vec3<B>> for Vec3<A> where A:From<B> {
    fn from(b:Vec3<B>)->Self {
        Vec3::<A>{ x: b.x.into(), y: b.y.into(), z: b.z.into() }        
    }
}
// error, conflicting impl in core..

I went through various experiments with a trait IsNot<B>{} , the best compromise for my use case was rolling that for types I care about and writing generic conversions to & from the ‘f32’ type.