0

I am trying to create a function for a struct which loops calling a function on itself, having trouble with lifetimes

The problem is in this function

fn next<'b, 'out>(reader_: &mut Reader<B> ) -> Option<(&'out [u8], BytesStart<'out>)> {
    let test = loop {
        let Reader { reader, ns, buf } = reader_;
        let e = reader
            .read_namespaced_event(buf, ns)
            .map(|(ns, e)| (ns.unwrap_or(&[]), e));
        match e {
            Ok((ns, Event::Start(start))) => {
                break Some((ns, start));
            }
            _ => {}
        }
    };
    test
}

I think the problem comes with the return value but i am not sure how to annotate the lifetimes.

Full code at: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=381cc6be43934c091b7444c4c8d80dfc

Using quick-xml.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
josepr
  • 3
  • 4
  • 2
    Your post is missing a lot of declarations (`_Reader`, `BytesStart`, `Event`, and functions) and doesn't include the error message. Please reproduce your problem on the [playground](https://play.rust-lang.org/) if you can. Your previous version you posted looked more complete. – kmdreko Aug 15 '21 at 01:26
  • 1
    It is often helpful (both to answerers _and_ askers) to create a [reprex]. Simplifying the code to the absolute minimum that creates the same error can help understand the problem more clearly. – Peter Hall Aug 15 '21 at 04:22
  • Unfortunately, this looks like one of these questions: https://stackoverflow.com/questions/50519147/double-mutable-borrow-error-in-a-loop-happens-even-with-nll-on – kmdreko Aug 15 '21 at 04:24

0 Answers0