refactor: satisfy clippy::manual_slice_size_calculation

This commit is contained in:
Erich Gubler 2023-07-25 11:19:32 -04:00 committed by Connor Fitzgerald
parent adc43b5672
commit 2492956014
3 changed files with 4 additions and 8 deletions

View File

@ -12,9 +12,9 @@ use winit::{
#[allow(dead_code)]
pub fn cast_slice<T>(data: &[T]) -> &[u8] {
use std::{mem::size_of, slice::from_raw_parts};
use std::{mem::size_of_val, slice::from_raw_parts};
unsafe { from_raw_parts(data.as_ptr() as *const u8, data.len() * size_of::<T>()) }
unsafe { from_raw_parts(data.as_ptr() as *const u8, size_of_val(data)) }
}
#[allow(dead_code)]

View File

@ -75,8 +75,7 @@ async fn execute_gpu_inner(
});
// Gets the size in bytes of the buffer.
let slice_size = numbers.len() * std::mem::size_of::<u32>();
let size = slice_size as wgpu::BufferAddress;
let size = std::mem::size_of_val(numbers) as wgpu::BufferAddress;
// Instantiates buffer without data.
// `usage` of buffer specifies how it can be used:

View File

@ -49,10 +49,7 @@ impl super::CommandBuffer {
fn add_push_constant_data(&mut self, data: &[u32]) -> Range<u32> {
let data_raw = unsafe {
std::slice::from_raw_parts(
data.as_ptr() as *const _,
data.len() * mem::size_of::<u32>(),
)
std::slice::from_raw_parts(data.as_ptr() as *const _, mem::size_of_val(data))
};
let start = self.data_bytes.len();
assert!(start < u32::MAX as usize);