mirror of
https://github.com/encounter/rust-sdl2.git
synced 2026-07-10 21:18:41 -07:00
Fix wrong lifetime in ttf::load_font
Closes #576 Adapted load_font to use AsRef<Path> as well
This commit is contained in:
@@ -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<Font, String> {
|
||||
pub fn load_font<'a, P: AsRef<Path>>(&'a self, path: P, point_size: u16) -> Result<Font, String> {
|
||||
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<Path>>(&'a self, path: P, index: u32, point_size: u16)
|
||||
-> Result<Font, String> {
|
||||
internal_load_font_at_index(path, index, point_size)
|
||||
}
|
||||
|
||||
@@ -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<Font, String> {
|
||||
pub fn internal_load_font<'a,P:AsRef<Path>>(path: P, ptsize: u16) -> Result<Font<'a>, 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<R
|
||||
}
|
||||
|
||||
/// Internally used to load a font (for internal visibility).
|
||||
pub fn internal_load_font_at_index(path: &Path, index: u32, ptsize: u16)
|
||||
-> Result<Font, String> {
|
||||
pub fn internal_load_font_at_index<'a,P: AsRef<Path>>(path: P, index: u32, ptsize: u16)
|
||||
-> Result<Font<'a>, 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);
|
||||
|
||||
Reference in New Issue
Block a user