Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kimonp committed Dec 21, 2023
1 parent f9dee93 commit 313bb9d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/bindgen_glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn request_animation_frame(f: &Closure<dyn FnMut()>) -> i32 {
.expect("should register `requestAnimationFrame` OK")
}

pub fn cancel_animation_frame(animation_id: i32) -> () {
pub fn cancel_animation_frame(animation_id: i32) {
window().cancel_animation_frame(animation_id).expect("Unable to cancel animation_frame")
}

Expand Down
3 changes: 2 additions & 1 deletion src/frames_per_second.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ max of last 100 = {max}

self.last_timeframe_stamp = now;

let latest_fps = 1 as f64 / delta * 1000 as f64;
let latest_fps = 1_f64 / delta * 1000_f64;
self.frames.push_front(latest_fps);

if self.frames.len() > 100 {
self.frames.pop_back();
}

let element_id = &self.element_id;
#[allow(clippy::expect_fun_call)]
let element = document().get_element_by_id(element_id).expect(&format!("Could not find element {element_id}"));
element.set_text_content(Some(&self.text()))
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ fn draw_cells(universe: &Universe) {
fill_cells(&context, cells, Cell::Dead);
}

fn fill_cells(context: &CanvasRenderingContext2d, cells: &Vec<Cell>, cell_type: Cell) {
fn fill_cells(context: &CanvasRenderingContext2d, cells: &[Cell], cell_type: Cell) {
for row in 0..GRID_ROWS {
for col in 0..GRID_COLUMNS {
let index = get_grid_index(row, col);
Expand Down Expand Up @@ -203,7 +203,7 @@ pub fn update_frame_loop(universe: Rc<Mutex<Universe>>) {
frames_per_second.update_frame();
let id = request_animation_frame(f.borrow().as_ref().unwrap());

if check == false {
if !check {
config_canvas(universe.clone());
check = true;
}
Expand Down
9 changes: 6 additions & 3 deletions src/universe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ pub struct Universe {
cells: Vec<Cell>,
}

fn get_random_int(max: u32) -> u32 {
Math::abs(Math::floor(Math::random() * max as f64)) as u32
}
impl Default for Universe { fn default() -> Self { Self::new() } }

impl Universe {
/// Create a new universe with the standard height and width.
Expand Down Expand Up @@ -178,3 +176,8 @@ impl Universe {
}
}
}

fn get_random_int(max: u32) -> u32 {
Math::abs(Math::floor(Math::random() * max as f64)) as u32
}

0 comments on commit 313bb9d

Please sign in to comment.