fixed vec mut slice

This commit is contained in:
Intege-rs
2025-01-05 01:58:27 -05:00
parent 16693d91a0
commit 0bc1ede256

View File

@@ -52,6 +52,11 @@ impl<const MAX_LEN: usize, T: Sized> FixedVec<MAX_LEN, T> {
unsafe { core::slice::from_raw_parts(self.buffer.as_ptr() as *const T, self.length) } unsafe { core::slice::from_raw_parts(self.buffer.as_ptr() as *const T, self.length) }
} }
pub fn as_slice_mut(&mut self) -> &mut [T] {
// length can't be larger than MaxLen, use unsafe to dodge the panic
unsafe { core::slice::from_raw_parts_mut(self.buffer.as_mut_ptr() as *mut T, self.length) }
}
pub fn clear(&mut self) { pub fn clear(&mut self) {
self.length = 0; self.length = 0;
} }