Struct shredder::Gc [−][src]
Expand description
A smart-pointer for data tracked by shredder
garbage collector
This lets you store arbitrary Scan
data on the heap, even if that data has cycles. If you
want to understand Scan
and implement it for your type, see the documentation of Scan
and
the provided Scan
derive.
Implementations
Create a new Gc
containing the given data.
When this data is garbage collected, its drop
implementation will be run.
T: GcDrop
in order to create a Gc<T>
with this method.
If your T
is not GcDrop
, consider new_with_finalizer
.
It is possible for this data not to be collected before the program terminates, or for the program to terminate before the background thread runs its destructor. So be careful when relying on this guarantee.
Create a new Gc
containing the given data. (But specifying not to run its destructor.)
This is useful because T: GcDrop
is no longer necessary!
When this data is garbage collected, its drop
implementation will NOT be run.
Be careful using this method! It can lead to memory leaks!
Create a new Gc
containing the given data. (But specifying to call finalize
on it
instead of running its destructor.)
This is useful because T: GcDrop
is no longer necessary! (See the documentation of
GcDrop
to understand why a piece of data may not be GcDrop
.)
As long as finalize
does what you think it does, this is probably what you want for
non-'static
/non-GcDrop
data!
It is possible for this data not to be collected before the program terminates, or for
the program to terminate before the background thread runs finalize
. So be careful not
to rely on this guarantee!
Create a new Gc
using the given Box<T>
.
This function does not allocate anything - rather, it uses the Box<T>
and releases its
memory appropriately. This is useful since it removes the requirement for types to be
sized.
get
lets you get a GcGuard
, which will deref to the underlying data.
get
is used to get a GcGuard
. This is usually what you want when accessing non-Sync
data in a Gc
. The API is very analogous to the Mutex
API. It may block if the data is
being scanned.
If you wish to avoid this, consider GcDeref
as an alternative.
Call the underlying borrow
method on the RefCell
.
This is just a nice method so you don’t have to call get
manually.
Call the underlying try_borrow
method on the RefCell
.
This is just a nice method so you don’t have to call get
manually.
Errors
Propagates a BorrowError
if the underlying RefCell
is already borrowed mutably
Call the underlying borrow_mut
method on the RefCell
.
This is just a nice method so you don’t have to call get
manually.
Call the underlying try_borrow_mut
method on the RefCell
.
This is just a nice method so you don’t have to call get
manually.
Errors
Propagates a BorrowError
if the underlying RefCell
is already borrowed
Call the underlying lock
method on the inner Mutex
This is just a nice method so you don’t have to get
manually
Errors
Returns a GcPoisonError
if the underlying .lock
method returns a poison error.
You may use into_inner
in order to recover the guard from that error.
Call the underlying try_lock
method on the inner Mutex
This is just a nice method so you don’t have to get
manually
Errors
Returns a GcTryLockError
if the underlying .try_lock
method returns an error
pub fn read(
&self
) -> Result<GcRwLockReadGuard<'_, T>, GcPoisonError<GcRwLockReadGuard<'_, T>>>
pub fn read(
&self
) -> Result<GcRwLockReadGuard<'_, T>, GcPoisonError<GcRwLockReadGuard<'_, T>>>
Call the underlying read
method on the inner RwLock
This is just a nice method so you don’t have to get
manually
Errors
Returns a GcPoisonError
if the underlying read
method returns a poison error.
You may use into_inner
in order to recover the guard from that error.
pub fn write(
&self
) -> Result<GcRwLockWriteGuard<'_, T>, GcPoisonError<GcRwLockWriteGuard<'_, T>>>
pub fn write(
&self
) -> Result<GcRwLockWriteGuard<'_, T>, GcPoisonError<GcRwLockWriteGuard<'_, T>>>
Call the underlying write
method on the inner RwLock
This is just a nice method so you don’t have to get
manually
Errors
Returns a GcPoisonError
if the underlying write
method returns a poison error.
You may use into_inner
in order to recover the guard from that error.
pub fn try_read(
&self
) -> Result<GcRwLockReadGuard<'_, T>, GcTryLockError<GcRwLockReadGuard<'_, T>>>
pub fn try_read(
&self
) -> Result<GcRwLockReadGuard<'_, T>, GcTryLockError<GcRwLockReadGuard<'_, T>>>
Call the underlying try_read
method on the inner RwLock
This is just a nice method so you don’t have to get
manually
Errors
Returns a GcTryLockError
if the underlying try_read
method returns an error
pub fn try_write(
&self
) -> Result<GcRwLockWriteGuard<'_, T>, GcTryLockError<GcRwLockWriteGuard<'_, T>>>
pub fn try_write(
&self
) -> Result<GcRwLockWriteGuard<'_, T>, GcTryLockError<GcRwLockWriteGuard<'_, T>>>
Call the underlying try_write
method on the inner RwLock
This is just a nice method so you don’t have to get
manually
Errors
Returns a GcTryLockError
if the underlying try_write
method returns an error
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
Blanket Implementations
Mutably borrows from an owned value. Read more