|
20 | 20 | phantom: PhantomData,
|
21 | 21 | }
|
22 | 22 | }
|
| 23 | + |
| 24 | + /// SAFETY: The index must point into the slice and must not be reused concurrently. |
| 25 | + #[allow(unsafe_code)] |
| 26 | + pub unsafe fn get_mut(&self, index: usize) -> &'a mut T { |
| 27 | + // SAFETY: The children array is alive by the 'a lifetime. |
| 28 | + unsafe { &mut *self.items.add(index) } |
| 29 | + } |
23 | 30 | }
|
24 | 31 |
|
25 | 32 | /// 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
|
@@ -72,15 +79,12 @@ impl<'a, T: Send> Node<'a, T> {
|
72 | 79 | /// Children are `Node`s referring to pack entries whose base object is this pack entry.
|
73 | 80 | pub fn into_child_iter(self) -> impl Iterator<Item = Node<'a, T>> + 'a {
|
74 | 81 | let children = self.child_items;
|
75 |
| - self.item.children.iter().map(move |&index| { |
76 |
| - // SAFETY: The children array is alive by the 'a lifetime. |
77 |
| - // SAFETY: The index is a valid index into the children array. |
78 |
| - // SAFETY: The resulting mutable pointer cannot be yielded by any other node. |
79 |
| - #[allow(unsafe_code)] |
80 |
| - Node { |
81 |
| - item: unsafe { &mut *children.items.add(index as usize) }, |
82 |
| - child_items: children.clone(), |
83 |
| - } |
| 82 | + // SAFETY: The index is a valid index into the children array. |
| 83 | + // SAFETY: The resulting mutable pointer cannot be yielded by any other node. |
| 84 | + #[allow(unsafe_code)] |
| 85 | + self.item.children.iter().map(move |&index| Node { |
| 86 | + item: unsafe { children.get_mut(index as usize) }, |
| 87 | + child_items: children.clone(), |
84 | 88 | })
|
85 | 89 | }
|
86 | 90 | }
|
0 commit comments