Skip to content

Removes boxed closures to compile w/ latest nightly. #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/sdl2/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,8 @@ impl Texture {
}
}

pub fn with_lock(&self, rect: Option<Rect>, func: |CVec<u8>, i32| -> ()) -> SdlResult<()> {
pub fn with_lock<F>(&self, rect: Option<Rect>, func: F) -> SdlResult<()>
where F: Fn(CVec<u8>, i32) -> () {
match self.unsafe_lock(rect) {
Ok((cvec, pitch)) => {
func(cvec, pitch);
Expand Down Expand Up @@ -649,7 +650,8 @@ impl Texture {
unsafe { ll::SDL_GL_UnbindTexture(self.raw) == 0 }
}

pub fn gl_with_bind<R>(&self, f: |tex_w: f64, tex_h: f64| -> R) -> R {
pub fn gl_with_bind<R,F>(&self, f: F) -> R
where F: Fn(f64, f64) -> R {
unsafe {
let texw: c_float = 0.0;
let texh: c_float = 0.0;
Expand Down
3 changes: 2 additions & 1 deletion src/sdl2/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ impl Surface {
}

/// Locks a surface so that the pixels can be directly accessed safely.
pub fn with_lock<R>(&mut self, f: |pixels: &mut [u8]| -> R) -> R {
pub fn with_lock<R,F>(&mut self, f: F) -> R
where F: Fn(&mut [u8]) -> R {
unsafe {
if ll::SDL_LockSurface(self.raw) != 0 { panic!("could not lock surface"); }

Expand Down
9 changes: 5 additions & 4 deletions src/sdl2/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ pub fn delay(ms: uint) {
pub struct Timer<'a> {
delay: uint,
raw: ll::SDL_TimerID,
closure: raw::Closure,
closure: raw::TraitObject,
remove_on_drop: bool,
lifetime: ContravariantLifetime<'a>,
}

impl<'a> Timer<'a> {
pub fn new(delay: uint, callback: ||: 'a -> uint, remove_on_drop: bool) -> Timer<'a> {
pub fn new<F>(delay: uint, callback: F, remove_on_drop: bool) -> Timer<'a>
where F: Fn() -> uint, F: 'a {
unsafe {
let c_param = mem::transmute::<_, raw::Closure>(callback);
let c_param = mem::transmute(&callback as &Fn() -> uint);
Timer { delay: delay, raw: 0, closure: c_param, remove_on_drop: remove_on_drop, lifetime: ContravariantLifetime }
}
}
Expand Down Expand Up @@ -74,6 +75,6 @@ impl<'a> Drop for Timer<'a> {
}

extern "C" fn c_timer_callback(_interval: uint32_t, param: *const c_void) -> uint32_t {
let f : &mut || -> uint = unsafe { mem::transmute(param) };
let f: &&Fn() -> uint = unsafe { mem::transmute(param) };
(*f)() as uint32_t
}