Need some help with the following error message.
error[E0277]: the trait bound `std::vec::Vec<D>: std::iter::FromIterator<<D as std::ops::Neg>::Output>` is not satisfied
--> src/jq.rs:301:44
|
301 | Ok(thunk(doc)?.into_iter().map(|x| -x).collect())
| ^^^^^^^ a collection of type `std::vec::Vec<D>` cannot be built from an iterator
over elements of type `<D as std::ops::Neg>::Output`
|
= help: the trait `std::iter::FromIterator<<D as std::ops::Neg>::Output>` is not implemented for `std::vec::Vec<D>`
= help: consider adding a `where std::vec::Vec<D>: std::iter::FromIterator<<D as std::ops::Neg>::Output>` bound
Scenario happens in this function:
fn do_neg<D>(thunk: &mut Thunk, doc: D) -> Result<Vec<D>> where D: Document {
Ok(thunk(doc)?.into_iter().map(|x| -x).collect())
}
where Document trait is constrained as:
pub trait Document : Neg + Not + Mul + Div + Rem + Add + Sub {
}
and Thunk implements FnMut:
impl<D> FnMut<(D,)> for Thunk where D: Document {
The return value for FnMut's call_mut is Result<Vec>
We are unwrapping the return value and applying Neg op on each D in Vec.
and finally collecting them back as Vec. That is when type signatures are
not matching.
Am I doing any mistake here ? Is it possible to resolve this issue ?