Skip to content

Commit 28dd804

Browse files
committed
fixed readme example bugs
1 parent cc7c807 commit 28dd804

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ av_dump_format(
3333
For the uninitiated, the std includes lots of convenient ffi related utilities. E.g. using `std::slice::from_raw_parts`:
3434
```rust
3535
let ifmt_ctx: AVFormatContext = *ifmt_ctx;
36+
let nb_streams = (*ifmt_ctx).nb_streams as usize;
3637

3738
// Extract video/audio/etc. streams from our mp4 file
38-
let streams: &[AVStream] = std::slice::from_raw_parts(
39-
*ifmt_ctx.streams,
40-
ifmt_ctx.nb_streams as usize
41-
);
39+
let streams: Vec<AVStream> = std::slice::from_raw_parts((*ifmt_ctx).streams, nb_streams)
40+
.iter()
41+
.map(|x| *(*x))
42+
.collect::<Vec<AVStream>>();
4243

4344
// C bindings require zero for loops 😌 - instead turn C dynamic arrays into Rust array refs
44-
for stream in std::slice::from_raw_parts(*ifmt_ctx.streams, ifmt_ctx.nb_streams as usize) {
45-
/// ... stream is of type '&AVStream'
45+
for stream_ptr in std::slice::from_raw_parts((*ifmt_ctx).streams, nb_streams) {
46+
// ...
4647
}
4748
```
4849

0 commit comments

Comments
 (0)