Consider the trait below. A Parser is a type which can take an input string and turn it into a bunch of candidate result. Each candidate stores: (1) the byte index up until which the result was found, and (2) a number of substrings that have been captured.
pub trait Parser { type Iter<'txt> : Iterator<Item = (usize, Vec<&'txt str>)>; fn parse<'me, 'txt>(&'me self, input : &'txt str) -> Self::Iter<'txt>; } It is important that a parser's result is liftetime-independent of its output: a parser may outlive its result, and similarly a result should be valid even if the parser that it came from was dropped. A parser should also be lifetime-independent of the input string itself. The only relation is that a parser's result is dependent on the input string.
This works fine so far, but becomes tricky when I try this:
pub struct BoxResult<P>(pub P); impl<P> Parser for BoxResult<P> where P : Parser { type Iter<'txt> = Box<dyn Iterator<Item = (usize, Vec<&'txt str>)>>; fn parse<'me, 'txt>(&'me self, input : &'txt str) -> Self::Iter<'txt> { Box::new(self.0.parse(input)) } } This causes the compiler to suggest a bunch of things. All of which won't work without breaking the original lifetime dependencies mentioned above.
I assume, though I am not sure, that the problem would be fixed if I could express:
type Iter<'txt> = Box<dyn use<'txt> + Iterator<Item = (usize, Vec<&'txt str>)>> 1 post - 1 participant

