From 7ee32ee86395995affcfc482e77b86fa77ecbe16 Mon Sep 17 00:00:00 2001 From: Cobrand Date: Fri, 6 Jan 2017 14:32:47 +0100 Subject: [PATCH] Fix wrong lifetime in ttf::load_font Closes #576 Adapted load_font to use AsRef as well --- src/sdl2/ttf/context.rs | 4 ++-- src/sdl2/ttf/font.rs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sdl2/ttf/context.rs b/src/sdl2/ttf/context.rs index 1fa6913e..37c545b7 100644 --- a/src/sdl2/ttf/context.rs +++ b/src/sdl2/ttf/context.rs @@ -29,13 +29,13 @@ impl Drop for Sdl2TtfContext { impl Sdl2TtfContext { /// Loads a font from the given file with the given size in points. - pub fn load_font<'a>(&'a self, path: &'a Path, point_size: u16) -> Result { + pub fn load_font<'a, P: AsRef>(&'a self, path: P, point_size: u16) -> Result { internal_load_font(path, point_size) } /// Loads the font at the given index of the file, with the given /// size in points. - pub fn load_font_at_index<'a>(&'a self, path: &'a Path, index: u32, point_size: u16) + pub fn load_font_at_index<'a, P: AsRef>(&'a self, path: P, index: u32, point_size: u16) -> Result { internal_load_font_at_index(path, index, point_size) } diff --git a/src/sdl2/ttf/font.rs b/src/sdl2/ttf/font.rs index 421d37ff..acf20a03 100644 --- a/src/sdl2/ttf/font.rs +++ b/src/sdl2/ttf/font.rs @@ -271,9 +271,9 @@ impl<'a> Drop for Font<'a> { } /// Internally used to load a font (for internal visibility). -pub fn internal_load_font(path: &Path, ptsize: u16) -> Result { +pub fn internal_load_font<'a,P:AsRef>(path: P, ptsize: u16) -> Result, String> { unsafe { - let cstring = CString::new(path.to_str().unwrap()).unwrap(); + let cstring = CString::new(path.as_ref().to_str().unwrap()).unwrap(); let raw = ffi::TTF_OpenFont(cstring.as_ptr(), ptsize as c_int); if raw.is_null() { Err(get_error()) @@ -290,10 +290,10 @@ pub fn internal_load_font_from_ll<'a>(raw: *const ffi::TTF_Font, rwops: Option Result { +pub fn internal_load_font_at_index<'a,P: AsRef>(path: P, index: u32, ptsize: u16) + -> Result, String> { unsafe { - let cstring = CString::new(path.to_str().unwrap().as_bytes()) + let cstring = CString::new(path.as_ref().to_str().unwrap().as_bytes()) .unwrap(); let raw = ffi::TTF_OpenFontIndex(cstring.as_ptr(), ptsize as c_int, index as c_long);