fix(sharedptr): fix type of Deref

This commit is contained in:
2024-04-29 15:50:13 +02:00
parent f8d497f3e1
commit 72b2e58244

View File

@@ -24,14 +24,12 @@ impl<const N: usize> SharedPtr<'_, N> {
pub fn get_offset(&self) -> usize {
let allocator = ALLOCATOR.lock().unwrap();
unsafe {
allocator.get_offset(self.as_ptr())
}
unsafe { allocator.get_offset(self.as_ptr()) }
}
}
impl<'a, const N: usize> Deref for SharedPtr<'a, N> {
type Target = &'a mut [u8; N];
type Target = [u8; N];
fn deref(&self) -> &Self::Target {
&self.0
@@ -65,4 +63,12 @@ mod tests {
assert_eq!(x[0], 1);
drop(x);
}
#[test]
fn slice() {
let mut x = SharedPtr::<10>::new().unwrap();
x[0] = 1;
x[1] = 2;
assert_eq!(x[0..=1], [1, 2]);
}
}