When I do
seq += u64::from(rhs);
Everything works. But I'd prefer the syntax of rhs.into()
with that I'm currently getting,
error[E0283]: type annotations needed
--> src/sequence.rs:50:5
|
19 | seq += rhs.into();
| ^^ ---------- this method call resolves to `T`
| |
| cannot infer type for type parameter `T`
|
= note: cannot satisfy `_: Into<u64>`
= note: required because of the requirements on the impl of `AddAssign<_>` for `Sequence`
This .into()
syntax normally works. Why doesn't type inference work on binary operators +=
such that if the LHS only implements AddAssign<u64>
the RHS will coerce? And moreover, aside from using from
what is the syntax (if possible) to provide this type information to .into
that the compiler needs? I've tried things like .into::<u64>(rhs)
and that also doesn't work.
I am implementing AddAssign
like this,
impl<T: Into<u64>> AddAssign<T> for Sequence {
fn add_assign(&mut self, rhs: T) {...}
}
And From
like this,
impl From<Sequence> for u64 {
fn from(seq: Sequence)-> u64 { ... }
}