tomassedovic / tcod-rs

Rust bindings for libtcod 1.6.3 (the Doryen library/roguelike toolkit)
Do What The F*ck You Want To Public License
229 stars 45 forks source link

Make Map impl Clone #284

Closed nsmryan closed 5 years ago

nsmryan commented 5 years ago

I've run into some situations where it would be nice to copy a Map struct, and there is no way to do this currently without calling ffi functions.

It seems like Map could impl Clone and call TCOD_map_copy to allow new maps a little more ergonomically.

I can make a pull request for this if you want. The code I came up with is:

impl Clone for Map {
    fn clone(&self) -> Self {
        let (width, height) = self.size();
        let mut new_map = Map::new(width, height);

        unsafe {
            ffi::TCOD_map_copy(*self.as_native(), *new_map.as_native());
        }

        new_map
    }
}
tomassedovic commented 5 years ago

That looks good to me! Yes please, if you put up a PR, I'd be happy to review it.

tomassedovic commented 5 years ago

Closed via #285