#Found both positive and negative implementation of trait

8 messages · Page 1 of 1 (latest)

young gust
#

Hello,
I got a base struct named Vec3 which is a simple struct with 3 elements.
It implements multiples traits such as Add, Div, Mul, Neg, Sub.
I want to derive from this a type Point which derives only a subset of the traits above.
so I did

type Point = Vec3;
impl !Add for Point {}

but I get the error

Found both positive and negative implementation of trait

is there a way to define a type with only a subset of the impls?
I want to prevent the use of the function Point.add and also make sure that Point is a different type than Vec3 (so can't be compared etc)

quiet swan
#

Using type defines a type alias (usually for generics where a particular signature will be reused regularly, such as io::Result), not a distinct type. As such, writing implementations for the alias, effectively defines them for the type it's based on...

To define inherence-like behaviour, you will have to define a new struct as a newtype wrapper, containing the original type.

young gust
quiet swan
#

That's correct.

young gust
#

Seems to work, thanks a lot!

young gust
humble carbon
#

No; currently it is not possible to alias the names of fields in any way at all.

quiet swan
#

Implementing Deref may be suitable in this case...