format/stream: avoid unsoundness splitting Stream into StreamMut

This commit is contained in:
meh
2015-08-25 15:45:55 +02:00
parent d1fa9bd864
commit a282d85662
5 changed files with 220 additions and 126 deletions

View File

@ -0,0 +1,41 @@
use std::ops::Deref;
use ffi::*;
use ::Rational;
use super::Stream;
#[derive(Eq, PartialEq)]
pub struct StreamMut<'a> {
ptr: *mut AVStream,
imm: Stream<'a>,
}
impl<'a> StreamMut<'a> {
pub unsafe fn wrap(ptr: *mut AVStream) -> Self {
StreamMut { ptr: ptr, imm: Stream::wrap(ptr) }
}
pub unsafe fn as_ptr(&self) -> *const AVStream {
self.ptr as *const _
}
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVStream {
self.ptr
}
}
impl<'a> StreamMut<'a> {
pub fn set_frame_rate(&mut self, value: Rational) {
unsafe {
av_stream_set_r_frame_rate(self.as_mut_ptr(), value.into());
}
}
}
impl<'a> Deref for StreamMut<'a> {
type Target = Stream<'a>;
fn deref(&self) -> &Self::Target {
&self.imm
}
}