Skip to content

Commit

Permalink
Merge pull request #78 from tomassedovic/fix-unboxed-closures
Browse files Browse the repository at this point in the history
Fix unboxed closures
  • Loading branch information
tomassedovic committed Jan 13, 2015
2 parents 15aab66 + e412ffd commit 5682371
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tcod"
description = "The Rust bindings for the Doryen library (a.k.a. libtcod)."
version = "0.4.1"
version = "0.4.2"
homepage = "https://github.com/tomassedovic/tcod-rs"
repository = "https://github.com/tomassedovic/tcod-rs"
readme = "README.md"
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ impl Drop for Map {

enum PathInnerData<'a> {
Map(Map),
Callback(Box<FnMut<((i32, i32), (i32, i32)), f32>+'a>, Box<(usize, usize)>),
Callback(Box<FnMut((i32, i32), (i32, i32)) -> f32+'a>, Box<(usize, usize)>),
}

// We need to wrap the pointer in a struct so that we can implement a
Expand Down Expand Up @@ -452,7 +452,7 @@ extern "C" fn c_path_callback(xf: c_int, yf: c_int,
user_data: *mut c_void) -> c_float {
unsafe {
let ptr: &(usize, usize) = &*(user_data as *const (usize, usize));
let cb: &mut FnMut<((i32, i32), (i32, i32)), f32> = ::std::mem::transmute(*ptr);
let cb: &mut FnMut((i32, i32), (i32, i32)) -> f32 = ::std::mem::transmute(*ptr);
//cb.call_mut(((xf, yf), (xt, yt))) as c_float
cb((xf, yf), (xt, yt)) as c_float
}
Expand All @@ -465,7 +465,7 @@ impl<'a> AStarPath<'a> {
width: i32, height: i32, path_callback: T,
diagonal_cost: f32) -> AStarPath<'a> {
// Convert the closure to a trait object. This will turn it into a fat pointer:
let user_closure: Box<FnMut<((i32, i32), (i32, i32)), f32>> = Box::new(path_callback);
let user_closure: Box<FnMut((i32, i32), (i32, i32)) -> f32> = Box::new(path_callback);
unsafe {
let fat_ptr: (usize, usize) = ::std::mem::transmute(&*user_closure);
// Allocate the fat pointer on the heap:
Expand Down Expand Up @@ -612,7 +612,7 @@ impl<'a> DijkstraPath<'a> {
diagonal_cost: f32) -> DijkstraPath<'a> {
// NOTE: this is might be a bit confusing. See the
// AStarPath::new_from_callback implementation comments.
let user_closure: Box<FnMut<((i32, i32), (i32, i32)), f32>> = Box::new(path_callback);
let user_closure: Box<FnMut((i32, i32), (i32, i32)) -> f32> = Box::new(path_callback);
unsafe {
let fat_ptr: (usize, usize) = ::std::mem::transmute(&*user_closure);
let mut ptr: Box<(usize, usize)> = Box::new(fat_ptr);
Expand Down

0 comments on commit 5682371

Please sign in to comment.