From cf80b94cf2bda3ec38ddd4fbf68b3e05fa507cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 3 Dec 2019 18:53:37 +0100 Subject: [PATCH 1/6] Use the `?` operator instead of deprecated item 'try' --- src/sdl2/image/mod.rs | 8 ++++---- src/sdl2/mixer/mod.rs | 2 +- src/sdl2/ttf/font.rs | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/sdl2/image/mod.rs b/src/sdl2/image/mod.rs index cac8c1ae..517e3ff0 100644 --- a/src/sdl2/image/mod.rs +++ b/src/sdl2/image/mod.rs @@ -46,16 +46,16 @@ bitflags! { impl ::std::fmt::Display for InitFlag { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { if self.contains(InitFlag::JPG) { - try!(f.write_str("INIT_JPG ")); + f.write_str("INIT_JPG ")?; } if self.contains(InitFlag::PNG) { - try!(f.write_str("INIT_PNG ")); + f.write_str("INIT_PNG ")?; } if self.contains(InitFlag::TIF) { - try!(f.write_str("INIT_TIF ")); + f.write_str("INIT_TIF ")?; } if self.contains(InitFlag::WEBP) { - try!(f.write_str("INIT_WEBP ")); + f.write_str("INIT_WEBP ")?; } Ok(()) } diff --git a/src/sdl2/mixer/mod.rs b/src/sdl2/mixer/mod.rs index c704f41e..d83f35e9 100644 --- a/src/sdl2/mixer/mod.rs +++ b/src/sdl2/mixer/mod.rs @@ -239,7 +239,7 @@ impl Drop for Chunk { impl Chunk { /// Load file for use as a sample. pub fn from_file>(path: P) -> Result { - let raw = unsafe { mixer::Mix_LoadWAV_RW(try!(RWops::from_file(path, "rb")).raw(), 0) }; + let raw = unsafe { mixer::Mix_LoadWAV_RW(RWops::from_file(path, "rb")?.raw(), 0) }; if raw.is_null() { Err(get_error()) } else { diff --git a/src/sdl2/ttf/font.rs b/src/sdl2/ttf/font.rs index 3b341308..1fac3343 100644 --- a/src/sdl2/ttf/font.rs +++ b/src/sdl2/ttf/font.rs @@ -149,7 +149,7 @@ impl<'f,'text> PartialRendering<'f,'text> { /// for an explanation. pub fn solid<'b, T>(self, color: T ) -> FontResult> where T: Into { - let source = try!(self.text.convert()); + let source = self.text.convert()?; let color = color.into().into(); let raw = unsafe { match self.text { @@ -171,7 +171,7 @@ impl<'f,'text> PartialRendering<'f,'text> { /// for an explanation. pub fn shaded<'b, T>(self, color: T, background: T) -> FontResult> where T: Into { - let source = try!(self.text.convert()); + let source = self.text.convert()?; let foreground = color.into().into(); let background = background.into().into(); let raw = unsafe { @@ -194,7 +194,7 @@ impl<'f,'text> PartialRendering<'f,'text> { /// for an explanation. pub fn blended<'b, T>(self, color: T) -> FontResult> where T: Into { - let source = try!(self.text.convert()); + let source = self.text.convert()?; let color = color.into().into(); let raw = unsafe { match self.text { @@ -217,7 +217,7 @@ impl<'f,'text> PartialRendering<'f,'text> { /// for an explanation of the mode. pub fn blended_wrapped<'b, T>(self, color: T, wrap_max_width: u32) -> FontResult> where T: Into { - let source = try!(self.text.convert()); + let source = self.text.convert()?; let color = color.into().into(); let raw = unsafe { match self.text { @@ -334,7 +334,7 @@ impl<'ttf,'r> Font<'ttf,'r> { /// Returns the width and height of the given text when rendered using this /// font. pub fn size_of(&self, text: &str) -> FontResult<(u32, u32)> { - let c_string = try!(RenderableText::Utf8(text).convert()); + let c_string = RenderableText::Utf8(text).convert()?; let (res, size) = unsafe { let mut w = 0; // mutated by C code let mut h = 0; // mutated by C code @@ -353,7 +353,7 @@ impl<'ttf,'r> Font<'ttf,'r> { #[allow(unused_mut)] pub fn size_of_latin1(&self, text: &[u8]) -> FontResult<(u32, u32)> { - let c_string = try!(RenderableText::Latin1(text).convert()); + let c_string = RenderableText::Latin1(text).convert()?; let (res, size) = unsafe { let mut w : i32 = 0; // mutated by C code let mut h : i32 = 0; // mutated by C code From 3909078e2c8a448d6aea15cc2518bd153596b50c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 3 Dec 2019 18:56:17 +0100 Subject: [PATCH 2/6] Use u16 instead of deprecated item 'libc::uint16_t' --- src/sdl2/mixer/mod.rs | 44 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/sdl2/mixer/mod.rs b/src/sdl2/mixer/mod.rs index d83f35e9..b1b1f5e5 100644 --- a/src/sdl2/mixer/mod.rs +++ b/src/sdl2/mixer/mod.rs @@ -28,7 +28,7 @@ use std::str::from_utf8; use std::borrow::ToOwned; use std::path::Path; use libc::c_void; -use libc::{c_int, uint16_t, c_double, c_uint}; +use libc::{c_int, c_double, c_uint}; use ::get_error; use ::rwops::RWops; use ::version::Version; @@ -38,29 +38,27 @@ use sys::mixer; // This comes from SDL_audio.h #[allow(non_camel_case_types)] mod ll { - use libc::uint16_t; - - pub const AUDIO_U8: uint16_t = 0x0008; - pub const AUDIO_S8: uint16_t = 0x8008; - pub const AUDIO_U16LSB: uint16_t = 0x0010; - pub const AUDIO_S16LSB: uint16_t = 0x8010; - pub const AUDIO_U16MSB: uint16_t = 0x1010; - pub const AUDIO_S16MSB: uint16_t = 0x9010; - pub const AUDIO_U16: uint16_t = AUDIO_U16LSB; - pub const AUDIO_S16: uint16_t = AUDIO_S16LSB; - pub const AUDIO_S32LSB: uint16_t = 0x8020; - pub const AUDIO_S32MSB: uint16_t = 0x9020; - pub const AUDIO_S32: uint16_t = AUDIO_S32LSB; - pub const AUDIO_F32LSB: uint16_t = 0x8120; - pub const AUDIO_F32MSB: uint16_t = 0x9120; - pub const AUDIO_F32: uint16_t = AUDIO_F32LSB; - pub const AUDIO_U16SYS: uint16_t = AUDIO_U16LSB; - pub const AUDIO_S16SYS: uint16_t = AUDIO_S16LSB; - pub const AUDIO_S32SYS: uint16_t = AUDIO_S32LSB; - pub const AUDIO_F32SYS: uint16_t = AUDIO_F32LSB; + pub const AUDIO_U8: u16 = 0x0008; + pub const AUDIO_S8: u16 = 0x8008; + pub const AUDIO_U16LSB: u16 = 0x0010; + pub const AUDIO_S16LSB: u16 = 0x8010; + pub const AUDIO_U16MSB: u16 = 0x1010; + pub const AUDIO_S16MSB: u16 = 0x9010; + pub const AUDIO_U16: u16 = AUDIO_U16LSB; + pub const AUDIO_S16: u16 = AUDIO_S16LSB; + pub const AUDIO_S32LSB: u16 = 0x8020; + pub const AUDIO_S32MSB: u16 = 0x9020; + pub const AUDIO_S32: u16 = AUDIO_S32LSB; + pub const AUDIO_F32LSB: u16 = 0x8120; + pub const AUDIO_F32MSB: u16 = 0x9120; + pub const AUDIO_F32: u16 = AUDIO_F32LSB; + pub const AUDIO_U16SYS: u16 = AUDIO_U16LSB; + pub const AUDIO_S16SYS: u16 = AUDIO_S16LSB; + pub const AUDIO_S32SYS: u16 = AUDIO_S32LSB; + pub const AUDIO_F32SYS: u16 = AUDIO_F32LSB; } -pub type AudioFormat = uint16_t; +pub type AudioFormat = u16; pub const AUDIO_U8: AudioFormat = ll::AUDIO_U8; pub const AUDIO_S8: AudioFormat = ll::AUDIO_S8; @@ -196,7 +194,7 @@ pub fn close_audio() { /// Get the actual audio format in use by the opened audio device. pub fn query_spec() -> Result<(i32, AudioFormat, i32), String> { let mut frequency: c_int = 0; - let mut format: uint16_t = 0; + let mut format: u16 = 0; let mut channels: c_int = 0; let ret = unsafe { mixer::Mix_QuerySpec(&mut frequency, &mut format, &mut channels) }; if ret == 0 { From c0f6e6e7a517b33e4829935a5baad63b204485e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 3 Dec 2019 18:57:44 +0100 Subject: [PATCH 3/6] Use u32 instead of deprecated item 'libc::uint32_t' --- src/sdl2/gfx/framerate.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdl2/gfx/framerate.rs b/src/sdl2/gfx/framerate.rs index 81d05a52..72843adf 100644 --- a/src/sdl2/gfx/framerate.rs +++ b/src/sdl2/gfx/framerate.rs @@ -1,7 +1,7 @@ //! Framerate control use libc; -use libc::{c_void, uint32_t, size_t}; +use libc::{c_void, size_t}; use std::mem; use ::get_error; use sys::gfx; @@ -24,7 +24,7 @@ impl FPSManager { /// Set the framerate in Hz. pub fn set_framerate(&mut self, rate: u32) -> Result<(), String> { - let ret = unsafe { gfx::framerate::SDL_setFramerate(self.raw, rate as uint32_t) }; + let ret = unsafe { gfx::framerate::SDL_setFramerate(self.raw, rate as u32) }; match ret { 0 => Ok(()), _ => Err(get_error()) From 498fc04c9215bc36bd980fc72cfcf7c745c0b9e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 3 Dec 2019 18:59:13 +0100 Subject: [PATCH 4/6] Remove unneeded `mut` --- sdl2-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdl2-sys/build.rs b/sdl2-sys/build.rs index 25be7610..d0ef44bf 100644 --- a/sdl2-sys/build.rs +++ b/sdl2-sys/build.rs @@ -220,7 +220,7 @@ fn patch_sdl2(sdl2_source_path: &Path) { // ever have more than one hunk. assert!(added_file.len() == 1); let file_path = sdl2_source_path.join(added_file.path()); - let mut dst_file = fs::File::create(&file_path) + let dst_file = fs::File::create(&file_path) .expect(&format!( "Failed to create file {}", file_path.to_string_lossy())); From c776e040d9a677646b18e8a6758e17ed656d69d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 3 Dec 2019 19:04:30 +0100 Subject: [PATCH 5/6] Don't use trait objects without an explicit `dyn` --- src/sdl2/ttf/context.rs | 2 +- src/sdl2/ttf/font.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdl2/ttf/context.rs b/src/sdl2/ttf/context.rs index ad3d5721..52ca8b3b 100644 --- a/src/sdl2/ttf/context.rs +++ b/src/sdl2/ttf/context.rs @@ -96,7 +96,7 @@ impl error::Error for InitError { } } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { match *self { InitError::AlreadyInitializedError => { None diff --git a/src/sdl2/ttf/font.rs b/src/sdl2/ttf/font.rs index 1fac3343..14aa5681 100644 --- a/src/sdl2/ttf/font.rs +++ b/src/sdl2/ttf/font.rs @@ -69,7 +69,7 @@ impl error::Error for FontError { } } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { match *self { FontError::InvalidLatin1Text(ref error) => { Some(error) From f755874c87a355c26ccdb56ca19b288b939b6d9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 3 Dec 2019 19:13:13 +0100 Subject: [PATCH 6/6] Correctly place bitflags documentation --- src/sdl2/image/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdl2/image/mod.rs b/src/sdl2/image/mod.rs index 517e3ff0..e0d8144c 100644 --- a/src/sdl2/image/mod.rs +++ b/src/sdl2/image/mod.rs @@ -31,9 +31,9 @@ use get_error; use sys; use sys::image; -/// InitFlags are passed to init() to control which subsystem -/// functionality to load. bitflags! { + /// InitFlags are passed to init() to control which subsystem + /// functionality to load. pub struct InitFlag : u32 { const JPG = image::IMG_InitFlags_IMG_INIT_JPG as u32; const PNG = image::IMG_InitFlags_IMG_INIT_PNG as u32;