audio: Fix all clippy::use_self warnings

This commit is contained in:
Marijn Suijten 2021-04-29 22:49:26 +02:00
parent a36fe2a3f5
commit 66b60a0822
7 changed files with 47 additions and 58 deletions

View file

@ -142,7 +142,7 @@ impl AudioBuffer<Readable> {
pub fn from_buffer_readable(
buffer: gst::Buffer,
info: &crate::AudioInfo,
) -> Result<AudioBuffer<Readable>, gst::Buffer> {
) -> Result<Self, gst::Buffer> {
skip_assert_initialized!();
assert!(info.is_valid());
@ -162,7 +162,7 @@ impl AudioBuffer<Readable> {
let info = crate::AudioInfo::from_glib_none(
&audio_buffer.info as *const _ as *mut ffi::GstAudioInfo,
);
Ok(AudioBuffer {
Ok(Self {
audio_buffer,
buffer: Some(buffer),
info,
@ -177,7 +177,7 @@ impl AudioBuffer<Writable> {
pub fn from_buffer_writable(
buffer: gst::Buffer,
info: &crate::AudioInfo,
) -> Result<AudioBuffer<Writable>, gst::Buffer> {
) -> Result<Self, gst::Buffer> {
skip_assert_initialized!();
assert!(info.is_valid());
@ -197,7 +197,7 @@ impl AudioBuffer<Writable> {
let info = crate::AudioInfo::from_glib_none(
&audio_buffer.info as *const _ as *mut ffi::GstAudioInfo,
);
Ok(AudioBuffer {
Ok(Self {
audio_buffer,
buffer: Some(buffer),
info,
@ -252,8 +252,8 @@ impl ops::Deref for AudioBufferPtr {
fn deref(&self) -> &Self::Target {
match self {
AudioBufferPtr::Owned(ref b) => &*b,
AudioBufferPtr::Borrowed(ref b) => unsafe { b.as_ref() },
Self::Owned(ref b) => &*b,
Self::Borrowed(ref b) => unsafe { b.as_ref() },
}
}
}
@ -261,8 +261,8 @@ impl ops::Deref for AudioBufferPtr {
impl ops::DerefMut for AudioBufferPtr {
fn deref_mut(&mut self) -> &mut Self::Target {
match self {
AudioBufferPtr::Owned(ref mut b) => &mut *b,
AudioBufferPtr::Borrowed(ref mut b) => unsafe { b.as_mut() },
Self::Owned(ref mut b) => &mut *b,
Self::Borrowed(ref mut b) => unsafe { b.as_mut() },
}
}
}
@ -362,7 +362,7 @@ impl<'a> AudioBufferRef<&'a gst::BufferRef> {
&(*audio_buffer).info as *const _ as *mut ffi::GstAudioInfo,
);
let buffer = gst::BufferRef::from_ptr((*audio_buffer).buffer);
Borrowed::new(AudioBufferRef {
Borrowed::new(Self {
audio_buffer: AudioBufferPtr::Borrowed(ptr::NonNull::new_unchecked(
audio_buffer as *mut _,
)),
@ -375,7 +375,7 @@ impl<'a> AudioBufferRef<&'a gst::BufferRef> {
pub fn from_buffer_ref_readable<'b>(
buffer: &'a gst::BufferRef,
info: &'b crate::AudioInfo,
) -> Result<AudioBufferRef<&'a gst::BufferRef>, glib::BoolError> {
) -> Result<Self, glib::BoolError> {
skip_assert_initialized!();
assert!(info.is_valid());
@ -395,7 +395,7 @@ impl<'a> AudioBufferRef<&'a gst::BufferRef> {
let info = crate::AudioInfo::from_glib_none(
&audio_buffer.info as *const _ as *mut ffi::GstAudioInfo,
);
Ok(AudioBufferRef {
Ok(Self {
audio_buffer: AudioBufferPtr::Owned(audio_buffer),
buffer: Some(buffer),
info,
@ -418,7 +418,7 @@ impl<'a> AudioBufferRef<&'a mut gst::BufferRef> {
&(*audio_buffer).info as *const _ as *mut ffi::GstAudioInfo,
);
let buffer = gst::BufferRef::from_mut_ptr((*audio_buffer).buffer);
Borrowed::new(AudioBufferRef {
Borrowed::new(Self {
audio_buffer: AudioBufferPtr::Borrowed(ptr::NonNull::new_unchecked(audio_buffer)),
buffer: Some(buffer),
info,
@ -429,7 +429,7 @@ impl<'a> AudioBufferRef<&'a mut gst::BufferRef> {
pub fn from_buffer_ref_writable<'b>(
buffer: &'a mut gst::BufferRef,
info: &'b crate::AudioInfo,
) -> Result<AudioBufferRef<&'a mut gst::BufferRef>, glib::BoolError> {
) -> Result<Self, glib::BoolError> {
skip_assert_initialized!();
assert!(info.is_valid());
@ -449,7 +449,7 @@ impl<'a> AudioBufferRef<&'a mut gst::BufferRef> {
let info = crate::AudioInfo::from_glib_none(
&audio_buffer.info as *const _ as *mut ffi::GstAudioInfo,
);
Ok(AudioBufferRef {
Ok(Self {
audio_buffer: AudioBufferPtr::Owned(audio_buffer),
buffer: Some(buffer),
info,
@ -487,10 +487,7 @@ impl<'a> ops::Deref for AudioBufferRef<&'a mut gst::BufferRef> {
type Target = AudioBufferRef<&'a gst::BufferRef>;
fn deref(&self) -> &Self::Target {
unsafe {
&*(self as *const AudioBufferRef<&'a mut gst::BufferRef>
as *const AudioBufferRef<&'a gst::BufferRef>)
}
unsafe { &*(self as *const Self as *const Self::Target) }
}
}

View file

@ -17,7 +17,7 @@ impl AudioChannelPosition {
}
pub fn positions_to_mask(
positions: &[AudioChannelPosition],
positions: &[Self],
force_order: bool,
) -> Result<u64, glib::error::BoolError> {
assert_initialized_main_thread!();
@ -53,10 +53,7 @@ impl AudioChannelPosition {
}
}
pub fn positions_from_mask(
mask: u64,
positions: &mut [AudioChannelPosition],
) -> Result<(), glib::BoolError> {
pub fn positions_from_mask(mask: u64, positions: &mut [Self]) -> Result<(), glib::BoolError> {
assert_initialized_main_thread!();
if positions.len() > 64 {
@ -86,9 +83,7 @@ impl AudioChannelPosition {
}
}
pub fn positions_to_valid_order(
positions: &mut [AudioChannelPosition],
) -> Result<(), glib::BoolError> {
pub fn positions_to_valid_order(positions: &mut [Self]) -> Result<(), glib::BoolError> {
assert_initialized_main_thread!();
if positions.len() > 64 {
@ -129,10 +124,7 @@ impl AudioChannelPosition {
unsafe { ffi::gst_audio_channel_get_fallback_mask(channels as i32) }
}
pub fn check_valid_channel_positions(
positions: &[crate::AudioChannelPosition],
force_order: bool,
) -> bool {
pub fn check_valid_channel_positions(positions: &[Self], force_order: bool) -> bool {
assert_initialized_main_thread!();
if positions.len() > 64 {

View file

@ -36,17 +36,17 @@ impl AsMut<gst::StructureRef> for AudioConverterConfig {
impl Default for AudioConverterConfig {
fn default() -> Self {
AudioConverterConfig::new()
Self::new()
}
}
impl convert::TryFrom<gst::Structure> for AudioConverterConfig {
type Error = glib::BoolError;
fn try_from(v: gst::Structure) -> Result<AudioConverterConfig, Self::Error> {
fn try_from(v: gst::Structure) -> Result<Self, Self::Error> {
skip_assert_initialized!();
if v.name() == "GstAudioConverter" {
Ok(AudioConverterConfig(v))
Ok(Self(v))
} else {
Err(glib::bool_error!("Structure is no AudioConverterConfig"))
}
@ -56,14 +56,14 @@ impl convert::TryFrom<gst::Structure> for AudioConverterConfig {
impl<'a> convert::TryFrom<&'a gst::StructureRef> for AudioConverterConfig {
type Error = glib::BoolError;
fn try_from(v: &'a gst::StructureRef) -> Result<AudioConverterConfig, Self::Error> {
fn try_from(v: &'a gst::StructureRef) -> Result<Self, Self::Error> {
skip_assert_initialized!();
AudioConverterConfig::try_from(v.to_owned())
Self::try_from(v.to_owned())
}
}
impl From<AudioConverterConfig> for gst::Structure {
fn from(v: AudioConverterConfig) -> gst::Structure {
fn from(v: AudioConverterConfig) -> Self {
skip_assert_initialized!();
v.0
}
@ -71,7 +71,7 @@ impl From<AudioConverterConfig> for gst::Structure {
impl AudioConverterConfig {
pub fn new() -> Self {
AudioConverterConfig(gst::Structure::new_empty("GstAudioConverter"))
Self(gst::Structure::new_empty("GstAudioConverter"))
}
pub fn set_dither_method(&mut self, v: crate::AudioDitherMethod) {

View file

@ -99,7 +99,7 @@ impl crate::AudioFormat {
endianness: crate::AudioEndianness,
width: i32,
depth: i32,
) -> crate::AudioFormat {
) -> Self {
assert_initialized_main_thread!();
unsafe {
@ -150,14 +150,14 @@ impl str::FromStr for crate::AudioFormat {
}
impl PartialOrd for crate::AudioFormat {
fn partial_cmp(&self, other: &crate::AudioFormat) -> Option<std::cmp::Ordering> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
crate::AudioFormatInfo::from_format(*self)
.partial_cmp(&crate::AudioFormatInfo::from_format(*other))
}
}
impl Ord for crate::AudioFormat {
fn cmp(&self, other: &crate::AudioFormat) -> std::cmp::Ordering {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
crate::AudioFormatInfo::from_format(*self).cmp(&crate::AudioFormatInfo::from_format(*other))
}
}

View file

@ -21,9 +21,9 @@ impl FromGlib<i32> for AudioEndianness {
assert_initialized_main_thread!();
match value {
1234 => AudioEndianness::LittleEndian,
4321 => AudioEndianness::BigEndian,
_ => AudioEndianness::Unknown,
1234 => Self::LittleEndian,
4321 => Self::BigEndian,
_ => Self::Unknown,
}
}
}
@ -33,8 +33,8 @@ impl IntoGlib for AudioEndianness {
fn into_glib(self) -> i32 {
match self {
AudioEndianness::LittleEndian => 1234,
AudioEndianness::BigEndian => 4321,
Self::LittleEndian => 1234,
Self::BigEndian => 4321,
_ => 0,
}
}
@ -43,14 +43,14 @@ impl IntoGlib for AudioEndianness {
pub struct AudioFormatInfo(&'static ffi::GstAudioFormatInfo);
impl AudioFormatInfo {
pub fn from_format(format: crate::AudioFormat) -> AudioFormatInfo {
pub fn from_format(format: crate::AudioFormat) -> Self {
assert_initialized_main_thread!();
unsafe {
let info = ffi::gst_audio_format_get_info(format.into_glib());
assert!(!info.is_null());
AudioFormatInfo(&*info)
Self(&*info)
}
}
@ -213,14 +213,14 @@ impl PartialEq for AudioFormatInfo {
impl Eq for AudioFormatInfo {}
impl PartialOrd for AudioFormatInfo {
fn partial_cmp(&self, other: &AudioFormatInfo) -> Option<Ordering> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for AudioFormatInfo {
// See GST_AUDIO_FORMATS_ALL for the sorting algorithm
fn cmp(&self, other: &AudioFormatInfo) -> Ordering {
fn cmp(&self, other: &Self) -> Ordering {
self.depth()
.cmp(&other.depth())
.then_with(|| self.width().cmp(&other.width()))
@ -369,7 +369,7 @@ impl glib::translate::GlibPtrDefault for AudioFormatInfo {
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstAudioFormatInfo> for AudioFormatInfo {
type Storage = &'a AudioFormatInfo;
type Storage = &'a Self;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstAudioFormatInfo, Self> {
glib::translate::Stash(self.0, self)
@ -384,7 +384,7 @@ impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstAudioFormatInfo> for Audi
impl glib::translate::FromGlibPtrNone<*mut ffi::GstAudioFormatInfo> for AudioFormatInfo {
#[inline]
unsafe fn from_glib_none(ptr: *mut ffi::GstAudioFormatInfo) -> Self {
AudioFormatInfo(&*ptr)
Self(&*ptr)
}
}
@ -392,7 +392,7 @@ impl glib::translate::FromGlibPtrNone<*mut ffi::GstAudioFormatInfo> for AudioFor
impl glib::translate::FromGlibPtrNone<*const ffi::GstAudioFormatInfo> for AudioFormatInfo {
#[inline]
unsafe fn from_glib_none(ptr: *const ffi::GstAudioFormatInfo) -> Self {
AudioFormatInfo(&*ptr)
Self(&*ptr)
}
}

View file

@ -142,7 +142,7 @@ impl AudioInfo {
!self.0.finfo.is_null() && self.0.channels > 0 && self.0.rate > 0 && self.0.bpf > 0
}
pub fn from_caps(caps: &gst::CapsRef) -> Result<AudioInfo, glib::error::BoolError> {
pub fn from_caps(caps: &gst::CapsRef) -> Result<Self, glib::error::BoolError> {
skip_assert_initialized!();
unsafe {
@ -153,7 +153,7 @@ impl AudioInfo {
)) {
let info = info.assume_init();
let positions = array_init::array_init(|i| from_glib(info.position[i]));
Ok(AudioInfo(info, positions))
Ok(Self(info, positions))
} else {
Err(glib::bool_error!("Failed to create AudioInfo from caps"))
}
@ -303,7 +303,7 @@ impl AudioInfo {
impl Clone for AudioInfo {
fn clone(&self) -> Self {
unsafe { AudioInfo(ptr::read(&self.0), self.1) }
unsafe { Self(ptr::read(&self.0), self.1) }
}
}
@ -387,7 +387,7 @@ impl glib::translate::GlibPtrDefault for AudioInfo {
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstAudioInfo> for AudioInfo {
type Storage = &'a AudioInfo;
type Storage = &'a Self;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstAudioInfo, Self> {
glib::translate::Stash(&self.0, self)
@ -402,7 +402,7 @@ impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstAudioInfo> for AudioInfo
impl glib::translate::FromGlibPtrNone<*mut ffi::GstAudioInfo> for AudioInfo {
#[inline]
unsafe fn from_glib_none(ptr: *mut ffi::GstAudioInfo) -> Self {
AudioInfo(
Self(
ptr::read(ptr),
array_init::array_init(|i| from_glib((*ptr).position[i])),
)

View file

@ -76,7 +76,7 @@ impl Clone for AudioRingBufferSpec {
let spec = self.0;
gst::ffi::gst_mini_object_ref(spec.caps as *mut gst::ffi::GstMiniObject);
AudioRingBufferSpec(spec)
Self(spec)
}
}
}