Curious bororow checker problem getting image buffers from two camera streams

I have an application, where I have two cameras connected using the v4l API. I am getting images from the cameras, and the methods return &[u8] buffers which are owned by the v4l driver.

I need to synchronize the two cameras, so that their images are in sync, for that the procedure is the following:

  1. Get left_img: &[u8] = left_stream.next(); and right_img: &[u8] = right_stream.next(); from the two camera streams
  2. Given the two buffers, extract and compare their timestamps
  3. If the left camera is behind, we "refresh" left_img = left_stream.next();
  4. Else if the right camera is behind, we get the next right_img = right_stream.next();
  5. Return (left_img, right_img)

This synchronization logic is verbose and messy, and I want to abstract it out, but the Rust borrow checker does not allow me to. I have been able to make a case where I do almost exactly the thing I want to, but only for a single camera, but the minute I try to do it for two cameras, it breaks down. Could any one help me cracking this nut?

A greatly simplified example showing the issue is available on this link: Rust Playground

Any help and advice would be greatly appreciated!

This would probably be better to ask on https://users.rust-lang.org/

The internals forum (here) is for development of rustc (and supporting tools such as cargo) itself.

1 Like

Thanks! I didn't realize. I have cross-posted here: Curious bororow checker problem getting image buffers from two camera streams - help - The Rust Programming Language Forum

2 Likes