diff options
| author | HampusM <hampus@hampusmat.com> | 2025-04-22 18:06:59 +0200 | 
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2025-04-22 18:06:59 +0200 | 
| commit | fb47933690dfb54206e9f136902671b19ddd34e0 (patch) | |
| tree | ffdb6640ea896b69b0267a9526657b9ed454184f /ecs/src/util | |
| parent | d9ac86a1f6ec541a399794f9f81381753cfea5f6 (diff) | |
refactor(ecs): fix clippy lints
Diffstat (limited to 'ecs/src/util')
| -rw-r--r-- | ecs/src/util/array_vec.rs | 24 | 
1 files changed, 13 insertions, 11 deletions
| 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<Item, const CAPACITY: usize>  impl<Item, const CAPACITY: usize> ArrayVec<Item, CAPACITY>  { -    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<Item, const CAPACITY: usize> AsRef<[Item]> for ArrayVec<Item, CAPACITY>  {      fn as_ref(&self) -> &[Item]      { -        unsafe { transmute::<&[MaybeUninit<Item>], &[Item]>(&self.items[..self.len]) } +        let ptr = &raw const self.items[..self.len]; + +        unsafe { &*(ptr as *const [Item]) }      }  } @@ -77,11 +81,9 @@ impl<Item, const CAPACITY: usize> AsMut<[Item]> for ArrayVec<Item, CAPACITY>  {      fn as_mut(&mut self) -> &mut [Item]      { -        unsafe { -            transmute::<&mut [MaybeUninit<Item>], &mut [Item]>( -                &mut self.items[..self.len], -            ) -        } +        let ptr = &raw mut self.items[..self.len]; + +        unsafe { &mut *(ptr as *mut [Item]) }      }  } | 
