You mentioned here that you had some Boxes you thought were unnecessary - I think you were almost there, I pretty much just shuffled around the lifetimes you already had and got something that worked.
The main hurdle was:
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
--> src/text/mod.rs:465:54
|
465 | pub fn iter_all_changes<'x, 'slf>(&'slf self) -> impl Iterator<Item = Change<'x, T>> + 'slf
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: hidden type `FlatMap<std::slice::Iter<'slf, types::DiffOp>, impl Iterator, [closure@src/text/mod.rs:471:36: 471:68]>` captures the lifetime `'new` as defined on the impl at 383:12
--> src/text/mod.rs:383:12
|
383 | impl<'old, 'new, 'bufs, T: DiffableStr + ?Sized + 'old + 'new> TextDiff<'old, 'new, 'bufs, T> {
| ^^^^
Which states that:
the type we're hiding with impl Iterator, Flatmap, is capturing the lifetime 'new
but our type signature for impl Iterator doesn't contain the lifetime 'new
The only lifetime we use in impl Iterator is 'x. So all we need to do is add an additional bound that 'x: 'new, which then means that 'newis implicitly used in our final type signature.
The rest is just adding lifetime bounds on other functions that call this one until the compiler is happy.
You mentioned here that you had some
Box
es you thought were unnecessary - I think you were almost there, I pretty much just shuffled around the lifetimes you already had and got something that worked.The main hurdle was:
Which states that:
impl Iterator
,Flatmap
, is capturing the lifetime'new
impl Iterator
doesn't contain the lifetime'new
The only lifetime we use in
impl Iterator
is'x
. So all we need to do is add an additional bound that'x: 'new
, which then means that'new
is implicitly used in our final type signature.The rest is just adding lifetime bounds on other functions that call this one until the compiler is happy.