|
| 1 | +use std::marker::PhantomData; |
| 2 | + |
1 | 3 | use crate::cache::delta::Item;
|
2 | 4 |
|
3 |
| -pub struct ItemSliceSend<T>(*mut T) |
| 5 | +pub struct ItemSliceSend<'a, T> |
4 | 6 | where
|
5 |
| - T: Send; |
| 7 | + T: Send, |
| 8 | +{ |
| 9 | + items: *mut T, |
| 10 | + phantom: PhantomData<&'a T>, |
| 11 | +} |
6 | 12 |
|
7 |
| -impl<T> ItemSliceSend<T> |
| 13 | +impl<'a, T> ItemSliceSend<'a, T> |
8 | 14 | where
|
9 | 15 | T: Send,
|
10 | 16 | {
|
11 |
| - pub fn new(items: &mut [T]) -> Self { |
12 |
| - ItemSliceSend(items.as_mut_ptr()) |
| 17 | + pub fn new(items: &'a mut [T]) -> Self { |
| 18 | + ItemSliceSend { |
| 19 | + items: items.as_mut_ptr(), |
| 20 | + phantom: PhantomData, |
| 21 | + } |
13 | 22 | }
|
14 | 23 | }
|
15 | 24 |
|
16 | 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
|
17 | 26 | /// don't violate aliasing rules.
|
18 |
| -impl<T> Clone for ItemSliceSend<T> |
| 27 | +impl<T> Clone for ItemSliceSend<'_, T> |
19 | 28 | where
|
20 | 29 | T: Send,
|
21 | 30 | {
|
22 | 31 | fn clone(&self) -> Self {
|
23 |
| - ItemSliceSend(self.0) |
| 32 | + ItemSliceSend { |
| 33 | + items: self.items, |
| 34 | + phantom: self.phantom, |
| 35 | + } |
24 | 36 | }
|
25 | 37 | }
|
26 | 38 |
|
27 | 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.
|
28 | 40 | #[allow(unsafe_code)]
|
29 |
| -unsafe impl<T> Send for ItemSliceSend<T> where T: Send {} |
| 41 | +unsafe impl<T> Send for ItemSliceSend<'_, T> where T: Send {} |
30 | 42 |
|
31 | 43 | /// An item returned by `iter_root_chunks`, allowing access to the `data` stored alongside nodes in a [`Tree`].
|
32 | 44 | pub struct Node<'a, T: Send> {
|
33 | 45 | pub item: &'a mut Item<T>,
|
34 |
| - pub child_items: ItemSliceSend<Item<T>>, |
| 46 | + pub child_items: ItemSliceSend<'a, Item<T>>, |
35 | 47 | }
|
36 | 48 |
|
37 | 49 | impl<'a, T: Send> Node<'a, T> {
|
@@ -66,7 +78,7 @@ impl<'a, T: Send> Node<'a, T> {
|
66 | 78 | // SAFETY: The resulting mutable pointer cannot be yielded by any other node.
|
67 | 79 | #[allow(unsafe_code)]
|
68 | 80 | Node {
|
69 |
| - item: unsafe { &mut *children.0.add(index as usize) }, |
| 81 | + item: unsafe { &mut *children.items.add(index as usize) }, |
70 | 82 | child_items: children.clone(),
|
71 | 83 | }
|
72 | 84 | })
|
|
0 commit comments