Currently, the Guard and PoolGuard types borrow the Slab/Pool and return a guard with the 'a lifetime, where 'a is the lifetime of the Slab or Pool. This ensures that references to entries don't outlive the Slab/Pool that owns them.
However, the generic lifetime means that these guards may only be stored on the stack. They cannot be placed in any type which must have a 'static lifetime, or live on the heap for an unknown amount of time.
We might want to consider adding a way to check out an owned reference, when the Slab/Pool is in an Arc. Since &Arc<Self> is a valid receiver type, we can do this. In this case, we would return a different type of guard, which clones the Arced Pool/Slab into the guard. This would ensure that the reference keeps the slab that the referenced item lives in alive.
In this case, we would have to use an *const T (probably should actually be a NonNull) for the actual reference to the object. But, this is fine, since the Arc keeps the owner alive --- we just can't prove this to the compiler.
Feature Request
Currently, the
Guard
andPoolGuard
types borrow theSlab
/Pool
and return a guard with the'a
lifetime, where'a
is the lifetime of theSlab
orPool
. This ensures that references to entries don't outlive theSlab
/Pool
that owns them.However, the generic lifetime means that these guards may only be stored on the stack. They cannot be placed in any type which must have a
'static
lifetime, or live on the heap for an unknown amount of time.We might want to consider adding a way to check out an owned reference, when the
Slab
/Pool
is in anArc
. Since&Arc<Self>
is a valid receiver type, we can do this. In this case, we would return a different type of guard, which clones theArc
edPool
/Slab
into the guard. This would ensure that the reference keeps the slab that the referenced item lives in alive.In this case, we would have to use an
*const T
(probably should actually be aNonNull
) for the actual reference to the object. But, this is fine, since theArc
keeps the owner alive --- we just can't prove this to the compiler.