|
| 1 | +use std::marker::PhantomData; |
| 2 | + |
1 | 3 | use crate::cache::delta::Item;
|
2 | 4 |
|
3 |
| -pub struct ItemSliceSend<T>(pub *mut [T]) |
| 5 | +pub(crate) struct ItemSliceSend<'a, T> |
| 6 | +where |
| 7 | + T: Send, |
| 8 | +{ |
| 9 | + items: *mut T, |
| 10 | + phantom: PhantomData<&'a T>, |
| 11 | +} |
| 12 | + |
| 13 | +impl<'a, T> ItemSliceSend<'a, T> |
4 | 14 | where
|
5 |
| - T: Send; |
| 15 | + T: Send, |
| 16 | +{ |
| 17 | + pub fn new(items: &'a mut [T]) -> Self { |
| 18 | + ItemSliceSend { |
| 19 | + items: items.as_mut_ptr(), |
| 20 | + phantom: PhantomData, |
| 21 | + } |
| 22 | + } |
| 23 | +} |
6 | 24 |
|
7 | 25 | /// SAFETY: This would be unsafe if this would ever be abused, but it's used internally and only in a way that assure that the pointers
|
8 | 26 | /// don't violate aliasing rules.
|
9 |
| -impl<T> Clone for ItemSliceSend<T> |
| 27 | +impl<T> Clone for ItemSliceSend<'_, T> |
10 | 28 | where
|
11 | 29 | T: Send,
|
12 | 30 | {
|
13 | 31 | fn clone(&self) -> Self {
|
14 |
| - ItemSliceSend(self.0) |
| 32 | + ItemSliceSend { |
| 33 | + items: self.items, |
| 34 | + phantom: self.phantom, |
| 35 | + } |
15 | 36 | }
|
16 | 37 | }
|
17 | 38 |
|
18 | 39 | // SAFETY: T is `Send`, and we only ever access one T at a time. And, ptrs need that assurance, I wonder if it's always right.
|
19 | 40 | #[allow(unsafe_code)]
|
20 |
| -unsafe impl<T> Send for ItemSliceSend<T> where T: Send {} |
| 41 | +unsafe impl<T> Send for ItemSliceSend<'_, T> where T: Send {} |
21 | 42 |
|
22 | 43 | /// An item returned by `iter_root_chunks`, allowing access to the `data` stored alongside nodes in a [`Tree`].
|
23 |
| -pub struct Node<'a, T: Send> { |
| 44 | +pub(crate) struct Node<'a, T: Send> { |
24 | 45 | pub item: &'a mut Item<T>,
|
25 |
| - pub child_items: ItemSliceSend<Item<T>>, |
| 46 | + pub child_items: ItemSliceSend<'a, Item<T>>, |
26 | 47 | }
|
27 | 48 |
|
28 | 49 | impl<'a, T: Send> Node<'a, T> {
|
@@ -57,7 +78,7 @@ impl<'a, T: Send> Node<'a, T> {
|
57 | 78 | // SAFETY: The resulting mutable pointer cannot be yielded by any other node.
|
58 | 79 | #[allow(unsafe_code)]
|
59 | 80 | Node {
|
60 |
| - item: &mut unsafe { &mut *children.0 }[index as usize], |
| 81 | + item: unsafe { &mut *children.items.add(index as usize) }, |
61 | 82 | child_items: children.clone(),
|
62 | 83 | }
|
63 | 84 | })
|
|
0 commit comments