Use FnMut instead of Fn

This commit is contained in:
Yash Karandikar 2022-03-06 14:23:10 -06:00
parent 475166b573
commit 2d8e75acd3
Signed by: karx
GPG key ID: A794DA2529474BA5
2 changed files with 17 additions and 3 deletions

View file

@ -3,13 +3,25 @@ use std::cell::Cell;
use sdl2::{
render::Canvas,
video::{Window, WindowBuildError},
EventPump, IntegerOrSdlError,
IntegerOrSdlError,
};
pub use sdl2::event::Event;
pub use sdl2::keyboard::Keycode;
pub use sdl2::pixels::Color;
#[macro_export]
macro_rules! cloned {
($thing:ident => $e:expr) => {
let $thing = $thing.clone();
$e
};
($($thing:ident),* => $e:expr) => {
$( let $thing = $thing.clone(); )*
$e
}
}
#[derive(Debug)]
pub struct CatboxError(String);
@ -50,7 +62,7 @@ impl Game {
}
}
pub fn run<F: Fn(&mut Canvas<Window>, Vec<Event>)>(&self, func: F) -> Result<()> {
pub fn run<F: FnMut(&mut Canvas<Window>, Vec<Event>)>(&self, mut func: F) -> Result<()> {
let sdl_context = sdl2::init()?;
let video_subsystem = sdl_context.video()?;

View file

@ -3,8 +3,10 @@ use catbox::{Event, Game, Keycode};
fn main() {
let game = Game::new("catbox demo", 1000, 800);
let mut i = 0;
game.run(|canvas, event_pump| {
canvas.set_draw_color(catbox::Color::RGB(0, 59, 111));
i = (i + 1) % 255;
canvas.set_draw_color(catbox::Color::RGB(i, 64, 255));
canvas.clear();
for event in event_pump {
match event {