Conflicting Impl in From<T>

I have made a struct that wrappes two numbers together, but i get an error of conflicting implementations for the symbol impl<T> From<T> for T in core.
My defenition is diffrent right? I have two generics, with different trait bounds?

impl<F: Into<T>, T: From<F> + Default + Clone> From<Vec2<F>> for Vec2<T> {
    fn from(value: Vec2<F>) -> Self {
        Vec2::from(value.x.into(), value.y.into())
    }
}

Full impl found in docs:

#[unstable(feature = "exclusive_wrapper", issue = "98407")]
impl<T> From<T> for Exclusive<T> {
    #[inline]
    fn from(t: T) -> Self {
        Self::new(t)
    }
}

Is my feature automaticaly implemented or is this confliction in the way? Is there any way to override this?

The actual conflicting implementation is From<T> for T that conflicts with Vec2<T> from Vec2<T>. Without specialization (not expected anytime soon), your implementation will always conflict with the blanket one from the standard library.

Given that your Vec2 is meant to hold numbers, there is a limited number of concrete types that your trait can serve. So limited, that you might want to consider just implementing From<Vec2<Number>> for each Number = i8, i16, i32, ..., u128. You could further abstract the implementation into a declarative macro and not be too far off of your original generic implementation.

4 Likes