*: refactor setters to return self

This commit is contained in:
meh
2015-09-26 18:01:23 +02:00
parent 4747a5a123
commit 510e8604b6
16 changed files with 254 additions and 116 deletions

View File

@ -19,9 +19,9 @@ impl Audio {
#[inline]
pub unsafe fn alloc(&mut self, format: format::Sample, samples: usize, layout: ChannelLayout) {
self.set_format(format);
self.set_samples(samples);
self.set_channel_layout(layout);
self.set_format(format)
.set_samples(samples)
.set_channel_layout(layout);
av_frame_get_buffer(self.as_mut_ptr(), 0);
}
@ -58,10 +58,12 @@ impl Audio {
}
#[inline]
pub fn set_format(&mut self, value: format::Sample) {
pub fn set_format(&mut self, value: format::Sample) -> &mut Self {
unsafe {
(*self.as_mut_ptr()).format = mem::transmute::<AVSampleFormat, c_int>(value.into());
}
self
}
#[inline]
@ -72,10 +74,12 @@ impl Audio {
}
#[inline]
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
pub fn set_channel_layout(&mut self, value: ChannelLayout) -> &mut Self {
unsafe {
av_frame_set_channel_layout(self.as_mut_ptr(), value.bits() as int64_t);
}
self
}
#[inline]
@ -86,10 +90,12 @@ impl Audio {
}
#[inline]
pub fn set_channels(&mut self, value: u16) {
pub fn set_channels(&mut self, value: u16) -> &mut Self {
unsafe {
av_frame_set_channels(self.as_mut_ptr(), value as c_int);
}
self
}
#[inline]
@ -100,10 +106,12 @@ impl Audio {
}
#[inline]
pub fn set_rate(&mut self, value: u32) {
pub fn set_rate(&mut self, value: u32) -> &mut Self {
unsafe {
av_frame_set_sample_rate(self.as_mut_ptr(), value as c_int);
}
self
}
#[inline]
@ -114,10 +122,12 @@ impl Audio {
}
#[inline]
pub fn set_samples(&mut self, value: usize) {
pub fn set_samples(&mut self, value: usize) -> &mut Self {
unsafe {
(*self.as_mut_ptr()).nb_samples = value as c_int;
}
self
}
#[inline]