From b9f51cbd6d63d221d87dcab51858c16dffda31ac Mon Sep 17 00:00:00 2001 From: Crazy-Owl Date: Fri, 3 Feb 2017 13:36:01 +0300 Subject: [PATCH] Use AsRef instead of &Path --- src/sdl2/image/mod.rs | 18 +++++++++--------- src/sdl2/mixer/mod.rs | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/sdl2/image/mod.rs b/src/sdl2/image/mod.rs index 77c528a3..97567005 100755 --- a/src/sdl2/image/mod.rs +++ b/src/sdl2/image/mod.rs @@ -88,21 +88,21 @@ pub trait LoadSurface: Sized { // Self is only returned here to type hint to the compiler. // The syntax for type hinting in this case is not yet defined. // The intended return value is Result<~Surface, String>. - fn from_file(filename: &Path) -> Result; + fn from_file>(filename: P) -> Result; fn from_xpm_array(xpm: *const *const i8) -> Result; } /// Method extensions to Surface for saving to disk pub trait SaveSurface { - fn save(&self, filename: &Path) -> Result<(), String>; + fn save>(&self, filename: P) -> Result<(), String>; fn save_rw(&self, dst: &mut RWops) -> Result<(), String>; } impl<'a> LoadSurface for Surface<'a> { - fn from_file(filename: &Path) -> Result, String> { + fn from_file>(filename: P) -> Result, String> { //! Loads an SDL Surface from a file unsafe { - let c_filename = CString::new(filename.to_str().unwrap()).unwrap(); + let c_filename = CString::new(filename.as_ref().to_str().unwrap()).unwrap(); let raw = ffi::IMG_Load(c_filename.as_ptr() as *const _); if (raw as *mut ()).is_null() { Err(get_error()) @@ -126,10 +126,10 @@ impl<'a> LoadSurface for Surface<'a> { } impl<'a> SaveSurface for Surface<'a> { - fn save(&self, filename: &Path) -> Result<(), String> { + fn save>(&self, filename: P) -> Result<(), String> { //! Saves an SDL Surface to a file unsafe { - let c_filename = CString::new(filename.to_str().unwrap()).unwrap(); + let c_filename = CString::new(filename.as_ref().to_str().unwrap()).unwrap(); let status = ffi::IMG_SavePNG(self.raw(), c_filename.as_ptr() as *const _); if status != 0 { Err(get_error()) @@ -155,14 +155,14 @@ impl<'a> SaveSurface for Surface<'a> { /// Method extensions for creating Textures from a Renderer pub trait LoadTexture { - fn load_texture(&self, filename: &Path) -> Result; + fn load_texture>(&self, filename: P) -> Result; } impl<'a> LoadTexture for Renderer<'a> { - fn load_texture(&self, filename: &Path) -> Result { + fn load_texture>(&self, filename: P) -> Result { //! Loads an SDL Texture from a file unsafe { - let c_filename = CString::new(filename.to_str().unwrap()).unwrap(); + let c_filename = CString::new(filename.as_ref().to_str().unwrap()).unwrap(); let raw = ffi::IMG_LoadTexture(self.raw(), c_filename.as_ptr() as *const _); if (raw as *mut ()).is_null() { Err(get_error()) diff --git a/src/sdl2/mixer/mod.rs b/src/sdl2/mixer/mod.rs index ee95ce67..dd1de4cc 100644 --- a/src/sdl2/mixer/mod.rs +++ b/src/sdl2/mixer/mod.rs @@ -255,7 +255,7 @@ impl Drop for Chunk { impl Chunk { /// Load file for use as a sample. - pub fn from_file(path: &Path) -> Result { + pub fn from_file>(path: P) -> Result { let raw = unsafe { ffi::Mix_LoadWAV_RW(try!(RWops::from_file(path, "rb")).raw(), 0) }; if raw.is_null() { Err(get_error()) @@ -768,9 +768,9 @@ impl<'a> fmt::Debug for Music<'a> { impl<'a> Music<'a> { /// Load music file to use. - pub fn from_file(path: &Path) -> Result, String> { + pub fn from_file>(path: P) -> Result, String> { let raw = unsafe { - let c_path = CString::new(path.to_str().unwrap()).unwrap(); + let c_path = CString::new(path.as_ref().to_str().unwrap()).unwrap(); ffi::Mix_LoadMUS(c_path.as_ptr()) }; if raw.is_null() {