So I have a struct
#[derive(Clone, Debug)]
pub struct Polynomial {
pub coefficients: Vec<BIG>,
}
It has 2 MulAssign methods as follows
impl<B: Borrow<Self>> ops::MulAssign<B> for Polynomial {...}
impl ops::MulAssign<BIG> for Polynomial {...}
all pretty standard so far. All of this compiles and works as intended.
I am reimplementing this using generics so we can have polynomials of any type that implement Big. Specifically, we have a trait Trait with type big implementing Big. Trait also holds other traits that would need to be consistent with big.
trait Trait {
type big: Big; // this makes sure big works the same as BIG
type othertype: OtherType<big = Self::big>;
...
}
I attempted to create a generic polynomial for trait as below. Note that _Polynomial must be generic on Trait since some other functions (say for othertype) may need a polynomial using the same kind of Big.
#[derive(Clone, Debug)]
pub struct _Polynomial<T: Trait> {
pub coefficients: Vec<T::big>,
}
I also tried to recreate the MulAssign functions with headers below, and here is where my issue arises
impl<T: Curve, B: Borrow<Self>> ops::MulAssign<B> for _Polynomial<T> {...}
impl<T: Curve> ops::MulAssign<T::big> for _Polynomial<T> {...}
I get an error "conflicting implementation for polynomial::_Polynomial<_>
".
I mostly understand WHY this is happening (Conflicting implementations of trait in Rust, Unable to implement Into trait for a generic struct) but I couldn't get the work around in those posts, or any of the other workarounds I found online.
I am still confused about why the initial version compiles without any errors since the method could be considered overloaded (how do we know "BIG" doesn't implement Borrow?)
I have spent many hours working at this and while I feel like I've learned a lot digging through stack overflow posts I still haven't found a workaround that works.
Any and all help is appreciated, thanks!