1 use crate::loom::cell::UnsafeCell; 2 use crate::util::slab::{Entry, Generation}; 3 4 /// Stores an entry in the slab. 5 pub(super) struct Slot<T> { 6 next: UnsafeCell<usize>, 7 entry: T, 8 } 9 10 impl<T: Entry> Slot<T> { 11 /// Initialize a new `Slot` linked to `next`. 12 /// 13 /// The entry is initialized to a default value. new(next: usize) -> Slot<T>14 pub(super) fn new(next: usize) -> Slot<T> { 15 Slot { 16 next: UnsafeCell::new(next), 17 entry: T::default(), 18 } 19 } 20 get(&self) -> &T21 pub(super) fn get(&self) -> &T { 22 &self.entry 23 } 24 generation(&self) -> Generation25 pub(super) fn generation(&self) -> Generation { 26 self.entry.generation() 27 } 28 reset(&self, generation: Generation) -> bool29 pub(super) fn reset(&self, generation: Generation) -> bool { 30 self.entry.reset(generation) 31 } 32 next(&self) -> usize33 pub(super) fn next(&self) -> usize { 34 self.next.with(|next| unsafe { *next }) 35 } 36 set_next(&self, next: usize)37 pub(super) fn set_next(&self, next: usize) { 38 self.next.with_mut(|n| unsafe { 39 (*n) = next; 40 }) 41 } 42 } 43