fix(sharedptr): fix type of Deref
This commit is contained in:
@@ -24,14 +24,12 @@ impl<const N: usize> SharedPtr<'_, N> {
|
|||||||
pub fn get_offset(&self) -> usize {
|
pub fn get_offset(&self) -> usize {
|
||||||
let allocator = ALLOCATOR.lock().unwrap();
|
let allocator = ALLOCATOR.lock().unwrap();
|
||||||
|
|
||||||
unsafe {
|
unsafe { allocator.get_offset(self.as_ptr()) }
|
||||||
allocator.get_offset(self.as_ptr())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, const N: usize> Deref for SharedPtr<'a, N> {
|
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 {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.0
|
&self.0
|
||||||
@@ -65,4 +63,12 @@ mod tests {
|
|||||||
assert_eq!(x[0], 1);
|
assert_eq!(x[0], 1);
|
||||||
drop(x);
|
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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user