From fb47933690dfb54206e9f136902671b19ddd34e0 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 22 Apr 2025 18:06:59 +0200 Subject: refactor(ecs): fix clippy lints --- ecs/src/util/array_vec.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'ecs/src/util') diff --git a/ecs/src/util/array_vec.rs b/ecs/src/util/array_vec.rs index 648c976..13a0349 100644 --- a/ecs/src/util/array_vec.rs +++ b/ecs/src/util/array_vec.rs @@ -1,4 +1,4 @@ -use std::mem::{transmute, MaybeUninit}; +use std::mem::MaybeUninit; use std::ops::{Deref, DerefMut}; #[derive(Debug)] @@ -10,16 +10,18 @@ pub struct ArrayVec impl ArrayVec { - pub fn new() -> Self + #[inline] + #[must_use] + pub fn len(&self) -> usize { - Self::default() + self.len } #[inline] #[must_use] - pub fn len(&self) -> usize + pub fn is_empty(&self) -> bool { - self.len + self.len == 0 } pub fn push(&mut self, item: Item) @@ -69,7 +71,9 @@ impl AsRef<[Item]> for ArrayVec { fn as_ref(&self) -> &[Item] { - unsafe { transmute::<&[MaybeUninit], &[Item]>(&self.items[..self.len]) } + let ptr = &raw const self.items[..self.len]; + + unsafe { &*(ptr as *const [Item]) } } } @@ -77,11 +81,9 @@ impl AsMut<[Item]> for ArrayVec { fn as_mut(&mut self) -> &mut [Item] { - unsafe { - transmute::<&mut [MaybeUninit], &mut [Item]>( - &mut self.items[..self.len], - ) - } + let ptr = &raw mut self.items[..self.len]; + + unsafe { &mut *(ptr as *mut [Item]) } } } -- cgit v1.2.3-18-g5258