diff --git a/src/grid.rs b/src/grid.rs index 7871ab1..8449c69 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -114,11 +114,14 @@ where // We mutate grid buffers and read grid data. We use unsafe because we need shared/unique borrows on different fields of the same Grid struct. bufs.iter().enumerate().for_each(|(i, buf)| { let buf_ptr = *buf as *const Vec as *mut Vec; - unsafe { buf_ptr.as_mut() }.unwrap().fill(0.0); + // SAFETY! we can take these are raw pointers because we are + // getting it from a `&mut [Grid]` + let buf_ptr_mut = unsafe { buf_ptr.as_mut().unwrap_unchecked() }; + + buf_ptr_mut.fill(0.0); datas.iter().enumerate().for_each(|(j, other)| { let multiplier = attraction_table[i].as_ref()[j]; - unsafe { buf_ptr.as_mut() } - .unwrap() + buf_ptr_mut .iter_mut() .zip(*other) .for_each(|(to, from)| *to += from * multiplier)