error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in function call due to conflicting requirements
--> model/src/sort/sort_send.rs:107:28
|
107 | let sub_iter = self.data[0].score_tree_iter();
The problem is from Vec<Par>. Really dont know how to solve this error.
Trait objects like dyn Iterator have a default lifetime which is often 'static. If you don't want it to be 'static, you'll need some sort of lifetime parameter on your Node, like
enum Node<'a> {
// You may even want two lifetimes...
Children(Box<dyn Iterator<Item = Node<'a>> + 'a>),
// [other variants]
}
This lifetime parameter will need to show up wherever you use Node in a place were elision doesn't work (and you may want to use it in some of those cases too).
pub trait Sortable<'a, ITER> where ITER : Iterator<Item = Node<'a>> + 'a
It means the lifetime of returned Iterator must be covered by the Node's lifetime and the struct implements Sortable, right?
In short, Sortable > Iterator > Node , where > means lifetime overlapps the later
Well, it means that you're declaring a trait that's generic over a lifetime 'a and a type ITER, and ITER cannot be bound by a lifetime shorter than 'a, and ITER also implements Iterator with an associated type of Item = Node<'a>. All 'a must be the same for implementations of the trait. Coercion will often see you through, but sometimes you need to give things separate lifetimes (or just not bind lifetimes) so that the bounds of one won't force the bounds of the other.