1

I'm trying to simulate the behavior of this C code in Rust:

len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
                                 in_data, in_len,
                                 pts, dts, pos);
in_data += len;

in_data is a buffer. It can be advanced.

How can I do something similar with a slice? I know I can take a subslice, and I could even write a class that I can advance and then return a subslice.

But is there something in the default libraries that already does that? Something like a buffered slice reader? PS: one that does not copy again the slice, only owns it and returns subslices according to the += operator on it.

2
  • 1
    Something in the default libraries that’s simpler than a subslice? It’s just in_data = &in_data[len..];.
    – Ry-
    Commented Oct 5, 2020 at 2:20
  • 1
    FWIW, &[u8] implements std::io::Read, although this only works for byte slices.
    – rodrigo
    Commented Oct 5, 2020 at 18:40

1 Answer 1

7

Assuming you're not trying to move the end of the slice, you can reslice it with something like in_data = &in_data[len..]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.