pub(crate) struct Ref<K: Key> {
raw_key: K,
marker: PhantomData<K>,
bomb: DropBombCondition,
}
Expand description
An copy of a slotmap_careful::Key
K
, which is counted by a RefCount
Ie, a key of type K
with the property that it
keeps the refcounted data structure alive.
Must always be deleted using dispose
, not dropped.
In tests, dropping a RefCounted
will panic.
The Default
value does not contribute to a reference count,
and is fine to drop.
Fields§
§raw_key: K
Actual key (without generics)
marker: PhantomData<K>
Bind to the specific key type
bomb: DropBombCondition
Drop bomb
Also forces Ref
not to be Clone
Implementations§
Source§impl<K: Key> Ref<K>
impl<K: Key> Ref<K>
Sourcepub(crate) fn new(key: K, count: &mut Count<K>) -> Result<Self, Overflow>
pub(crate) fn new(key: K, count: &mut Count<K>) -> Result<Self, Overflow>
Create a refcounted reference Ref
from an un-counted key, incrementing the count
Sourcepub(crate) fn null() -> Self
pub(crate) fn null() -> Self
Creates a null Ref
, which doesn’t refer to any slot (lookups always give None
)
Sourcepub(crate) fn dispose(self, refcount: &mut Count<K>) -> Option<Garbage<K>>
pub(crate) fn dispose(self, refcount: &mut Count<K>) -> Option<Garbage<K>>
Dispose of a refcounted reference Ref
, decrementing the count
If the count reaches zero, the raw key is returned; the caller should remove the corresponding data from the data structure.
Sourcepub(crate) fn dispose_container_destroyed(self)
pub(crate) fn dispose_container_destroyed(self)
Dispose of a refcounted reference whose container no longer exists
§CORRECTNESS
This just forgets the reference, without decrementing any refcount. If the container does still exist, a ref count ref will be leaked.
Trait Implementations§
Source§impl<K: Key> DefaultExtTake for Ref<K>
impl<K: Key> DefaultExtTake for Ref<K>
Source§impl<K: Key> Ord for Ref<K>
impl<K: Key> Ord for Ref<K>
Source§impl<K: Key> PartialOrd for Ref<K>
impl<K: Key> PartialOrd for Ref<K>
impl<K: Key> Eq for Ref<K>
Auto Trait Implementations§
impl<K> Freeze for Ref<K>where
K: Freeze,
impl<K> RefUnwindSafe for Ref<K>where
K: RefUnwindSafe,
impl<K> Send for Ref<K>where
K: Send,
impl<K> Sync for Ref<K>where
K: Sync,
impl<K> Unpin for Ref<K>where
K: Unpin,
impl<K> UnwindSafe for Ref<K>where
K: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more