pub struct Handle<D: Send + Sync>(/* private fields */);
Expand description
Represents a resource handle.
The resource stays in memory as long as a handle clone is alive. After the handle is dropped the resource will be removed after an indeterminate time at the discretion of the resource manager.
You can forget a handle by calling perm
, this releases the handle memory
but the resource stays alive for the duration of the app, unlike calling std::mem::forget
no memory is leaked.
Any handle can also force_drop
, meaning that even if there are various handles active the
resource will be dropped regardless.
The parameter type D
is any Sync
data type that will be shared using the handle.
Implementations§
source§impl<D: Send + Sync> Handle<D>
impl<D: Send + Sync> Handle<D>
sourcepub fn new(data: D) -> (HandleOwner<D>, Handle<D>)
pub fn new(data: D) -> (HandleOwner<D>, Handle<D>)
Create a handle with owner pair.
sourcepub fn dummy(data: D) -> Self
pub fn dummy(data: D) -> Self
Create a handle to nothing, the handle always in the dropped state.
Note that Option<Handle<D>>
takes up the same space as Handle<D>
and avoids an allocation.
sourcepub fn perm(self)
pub fn perm(self)
Mark the handle as permanent and drops this clone of it. This causes the resource to stay in memory until the app exits, no need to hold a handle somewhere.
sourcepub fn is_permanent(&self) -> bool
pub fn is_permanent(&self) -> bool
If perm
was called in another clone of this handle.
If true
the resource will stay in memory for the duration of the app, unless force_drop
is also called.
sourcepub fn force_drop(self)
pub fn force_drop(self)
Force drops the handle, meaning the resource will be dropped even if there are other handles active.
sourcepub fn is_dropped(&self) -> bool
pub fn is_dropped(&self) -> bool
If the handle is in dropped state.
The handle is considered dropped when all handle and clones are dropped or when force_drop
was called in any of the clones.
Note that in this method it can only be because force_drop
was called.
sourcepub fn downgrade(&self) -> WeakHandle<D>
pub fn downgrade(&self) -> WeakHandle<D>
Create a WeakHandle
to this handle.
Trait Implementations§
impl<D: Send + Sync> Eq for Handle<D>
Auto Trait Implementations§
impl<D> Freeze for Handle<D>
impl<D> RefUnwindSafe for Handle<D>where
D: RefUnwindSafe,
impl<D> Send for Handle<D>
impl<D> Sync for Handle<D>
impl<D> Unpin for Handle<D>
impl<D> UnwindSafe for Handle<D>where
D: RefUnwindSafe,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)