Skip to content

Commit 56a183e

Browse files
authored
Merge pull request #74 from MichaelHills/mike-deprecation-warnings
Fix deprecation warnings
2 parents a843cfd + f7edf3f commit 56a183e

File tree

3 files changed

+32
-57
lines changed

3 files changed

+32
-57
lines changed

src/audio_unit/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct InputCallback {
8989

9090

9191
macro_rules! try_os_status {
92-
($expr:expr) => (try!(Error::from_os_status($expr)))
92+
($expr:expr) => (Error::from_os_status($expr)?)
9393
}
9494

9595

@@ -156,10 +156,11 @@ impl AudioUnit {
156156
}
157157

158158
// Create an instance of the default audio unit using the component.
159-
let mut instance: sys::AudioUnit = mem::uninitialized();
159+
let mut instance_uninit = mem::MaybeUninit::<sys::AudioUnit>::uninit();
160160
try_os_status!(
161-
sys::AudioComponentInstanceNew(component, &mut instance as *mut sys::AudioUnit)
161+
sys::AudioComponentInstanceNew(component, instance_uninit.as_mut_ptr() as *mut sys::AudioUnit)
162162
);
163+
let instance: sys::AudioUnit = instance_uninit.assume_init();
163164

164165
// Initialise the audio unit!
165166
try_os_status!(sys::AudioUnitInitialize(instance));
@@ -290,7 +291,7 @@ impl AudioUnit {
290291
/// Return the current Stream Format for the AudioUnit.
291292
pub fn stream_format(&self, scope: Scope) -> Result<StreamFormat, Error> {
292293
let id = sys::kAudioUnitProperty_StreamFormat;
293-
let asbd = try!(self.get_property(id, scope, Element::Output));
294+
let asbd = self.get_property(id, scope, Element::Output)?;
294295
StreamFormat::from_asbd(asbd)
295296
}
296297

@@ -391,12 +392,13 @@ pub fn get_property<T>(
391392
let elem = elem as c_uint;
392393
let mut size = ::std::mem::size_of::<T>() as u32;
393394
unsafe {
394-
let mut data: T = ::std::mem::uninitialized();
395-
let data_ptr = &mut data as *mut _ as *mut c_void;
395+
let mut data_uninit = ::std::mem::MaybeUninit::<T>::uninit();
396+
let data_ptr = data_uninit.as_mut_ptr() as *mut _ as *mut c_void;
396397
let size_ptr = &mut size as *mut _;
397398
try_os_status!(
398399
sys::AudioUnitGetProperty(au, id, scope, elem, data_ptr, size_ptr)
399400
);
401+
let data: T = data_uninit.assume_init();
400402
Ok(data)
401403
}
402404
}

src/audio_unit/render_callback.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use self::data::Data;
1414
///
1515
/// This allows the user to provide a custom, more rust-esque callback function type that takes
1616
/// greater advantage of rust's type safety.
17-
pub type InputProcFn = FnMut(*mut sys::AudioUnitRenderActionFlags,
17+
pub type InputProcFn = dyn FnMut(*mut sys::AudioUnitRenderActionFlags,
1818
*const sys::AudioTimeStamp,
1919
sys::UInt32,
2020
sys::UInt32,
@@ -398,7 +398,7 @@ impl AudioUnit {
398398
// First, we'll retrieve the stream format so that we can ensure that the given callback
399399
// format matches the audio unit's format.
400400
let id = sys::kAudioUnitProperty_StreamFormat;
401-
let asbd = try!(self.get_property(id, Scope::Input, Element::Output));
401+
let asbd = self.get_property(id, Scope::Input, Element::Output)?;
402402
let stream_format = super::StreamFormat::from_asbd(asbd)?;
403403

404404
// If the stream format does not match, return an error indicating this.

src/error.rs

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,7 @@ pub mod audio {
4545

4646
impl ::std::fmt::Display for Error {
4747
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
48-
write!(f, "{:?}", self)
49-
}
50-
}
51-
52-
impl ::std::error::Error for Error {
53-
fn description(&self) -> &str {
54-
match *self {
48+
let description = match *self {
5549
Error::Unimplemented => "Unimplemented",
5650
Error::FileNotFound => "File not found",
5751
Error::FilePermission => "File permission",
@@ -60,7 +54,8 @@ pub mod audio {
6054
Error::Param => "Param",
6155
Error::MemFull => "Memory full",
6256
Error::Unknown => "An unknown error occurred",
63-
}
57+
};
58+
write!(f, "{}", description)
6459
}
6560
}
6661

@@ -106,13 +101,7 @@ pub mod audio_codec {
106101

107102
impl ::std::fmt::Display for Error {
108103
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
109-
write!(f, "{:?}", self)
110-
}
111-
}
112-
113-
impl ::std::error::Error for Error {
114-
fn description(&self) -> &str {
115-
match *self {
104+
let description = match *self {
116105
Error::Unspecified => "Unspecified",
117106
Error::UnknownProperty => "Unknown property",
118107
Error::BadPropertySize => "Bad property size",
@@ -121,7 +110,8 @@ pub mod audio_codec {
121110
Error::State => "State",
122111
Error::NotEnoughBufferSpace => "Not enough buffer space",
123112
Error::Unknown => "Unknown error occurred",
124-
}
113+
};
114+
write!(f, "{}", description)
125115
}
126116
}
127117

@@ -161,21 +151,16 @@ pub mod audio_format {
161151

162152
impl ::std::fmt::Display for Error {
163153
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
164-
write!(f, "{:?}", self)
165-
}
166-
}
167-
168-
impl ::std::error::Error for Error {
169-
fn description(&self) -> &str {
170-
match *self {
154+
let description = match *self {
171155
Error::Unspecified => "An unspecified error",
172156
Error::UnsupportedProperty => "The specified property is not supported",
173157
Error::BadPropertySize => "Bad property size",
174158
Error::BadSpecifierSize => "Bad specifier size",
175159
Error::UnsupportedDataFormat => "The specified data format is not supported",
176160
Error::UnknownFormat => "The specified data format is not a known format",
177161
Error::Unknown => "Unknown error occurred",
178-
}
162+
};
163+
write!(f, "{}", description)
179164
}
180165
}
181166
}
@@ -239,13 +224,7 @@ pub mod audio_unit {
239224

240225
impl ::std::fmt::Display for Error {
241226
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
242-
write!(f, "{:?}", self)
243-
}
244-
}
245-
246-
impl ::std::error::Error for Error {
247-
fn description(&self) -> &str {
248-
match *self {
227+
let description = match *self {
249228
Error::InvalidProperty => "Invalid property",
250229
Error::InvalidParameter => "Invalid parameter",
251230
Error::InvalidElement => "Invalid element",
@@ -264,7 +243,8 @@ pub mod audio_unit {
264243
Error::InvalidOfflineRender => "Invalid offline render",
265244
Error::Unauthorized => "Unauthorized",
266245
Error::Unknown => "Unknown error occurred",
267-
}
246+
};
247+
write!(f, "{}", description)
268248
}
269249
}
270250

@@ -338,25 +318,18 @@ impl Error {
338318

339319
impl ::std::fmt::Display for Error {
340320
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
341-
write!(f, "{:?}", self)
342-
}
343-
}
344-
345-
impl ::std::error::Error for Error {
346-
fn description(&self) -> &str {
347321
match *self {
348-
Error::Unspecified => "An unspecified error has occurred",
349-
Error::NoMatchingDefaultAudioUnitFound => "No matching default audio unit found",
322+
Error::Unspecified => write!(f, "An unspecified error has occurred"),
323+
Error::NoMatchingDefaultAudioUnitFound => write!(f, "No matching default audio unit found"),
350324
Error::RenderCallbackBufferFormatDoesNotMatchAudioUnitStreamFormat =>
351-
"The given render callback buffer format does not match the `AudioUnit` `StreamFormat`",
352-
Error::SystemSoundClientMessageTimedOut => "The system sound client message timed out",
353-
Error::NoKnownSubtype => "The type has no known subtypes",
354-
Error::Audio(ref err) => err.description(),
355-
Error::AudioCodec(ref err) => err.description(),
356-
Error::AudioFormat(ref err) => err.description(),
357-
Error::AudioUnit(ref err) => err.description(),
358-
Error::Unknown(_) => "An unknown error unknown to the coreaudio-rs API occurred",
325+
write!(f, "The given render callback buffer format does not match the `AudioUnit` `StreamFormat`"),
326+
Error::SystemSoundClientMessageTimedOut => write!(f, "The system sound client message timed out"),
327+
Error::NoKnownSubtype => write!(f, "The type has no known subtypes"),
328+
Error::Audio(ref err) => write!(f, "{}", err),
329+
Error::AudioCodec(ref err) => write!(f, "{}", err),
330+
Error::AudioFormat(ref err) => write!(f, "{}", err),
331+
Error::AudioUnit(ref err) => write!(f, "{}", err),
332+
Error::Unknown(_) => write!(f, "An unknown error unknown to the coreaudio-rs API occurred"),
359333
}
360334
}
361335
}
362-

0 commit comments

Comments
 (0)