0

I'm trying to create an iterator of video frames from a packetiter. I need to filter out packets that are not from the video stream as in a video file there are multiple streams, audio, video etc

Let's say I have variable index which is the index of the stream i want to decode and I want to only decode packets from that stream

This gives me the following iterator everything past the filter iterator has been elided

let index = self.video_index; // unused variable Index
        self.input
            .packets()
            .filter(|(stream, _packet)| match stream.index() {
                index => true, //unused variable index
                _ => false,
            })

Now the predicate function for .filter can't access the outer scope. I don't know what index will be beforehand. How can I get the predicate function to match on stream.index() when index does not exist in the predicate's scope?

Brandon Piña
  • 614
  • 1
  • 6
  • 20
  • 2
    Using `index => true` introduces `index` as a new binding based on the matched value, it does not compare to the existing `index` variable. You would need to use a *match guard*: `i if i == index => true`. However, the entire `match` can be replaced with just `stream.index() == index`. – kmdreko Dec 12 '22 at 23:18
  • using stream.index() == index did the trick for me, thanks – Brandon Piña Dec 12 '22 at 23:27

0 Answers0