Struct tracing_rc::rc::Gc[][src]

pub struct Gc<T: Traceable + 'static> { /* fields omitted */ }
Expand description

A cycle-collected reference-counted smart pointer. Gc<T> provides shared ownership of a value of type T, allocated on the heap. Cloining it will produce a new Gc instance which pints to the same allocation as the original Gc.

Unlike std::rc::Rc, Gc pointers may refer to each other in a way that creates cycles arbitrarily without causing leaks, provided that the program calls collect to collect those cycles.

It’s important to note a few things about collection:

  • The default collect implementation only performs cycle-tracing collection if a node has been in waiting for collection for a while. This is so that we don’t pay the cost of tracing for acyclic nodes which may be marked for collection due to the number of outstanding references, but don’t actually participate in a cycle. You may use collect_full to force tracing collection of all pending nodes if you prefer.
  • Dropping of data is deferred until a call to collect or collect_full is made, and the collector is able to determine that the Gc is actually dead. The collector guarantees that (in the absence of bugs) the Drop implementation for your type will be executed if it is determined to be dead, but cannot provide any guarantees on when it will be executed.
    • collect has weak guarantees even in the presence of acyclic pointers - if a node containing your type is acyclic, but has N strong references, it may take up to min(N, [CollectionOptions::old_gen_threshold] + 1) calls to collect for the value to be cleaned up even if all parents are dropped.
    • The collector does guarantee that if collect_full is used, the Drop implementation for your data will have been executed by the time collect_full completes if the value is dead.
  • The collector does not make any guarantees about the relative order of drops for dead nodes. Even if the order appears stable, you may not rely on it for program correctness.

Implementations

Construct a new Gc containing data which will be automatically cleaned up with it is no longer reachable, even in the presence of cyclical references.

Retrieve the current number of strong references outstanding.

Returns true if the data in Self hasn’t been dropped yet. This will almost always be the case unless it is called inside of a Drop implementation or if there is a bug present in a Traceable impl.

Get a reference into this Gc.

Returns None if the pointer is dead, as the data contained in this pointer is possibly cleaned up.

Try to get a mutable referenced into this Gc. Will return None if there are oustanding strong references to this, or if the pointer is dead.

Gets a reference into this Gc without checking if pointer is still alive.

Safety

This gc pointer must not have had its inner data dropped yet

Gets a reference into this Gc without checking if pointer is still alive or has unique access

Safety
  • This gc pointer must not have had its inner data dropped yet.
  • There must be no other aliasing references to the inner data.

Returns true if both this & other point to the same allocation.

Trait Implementations

Performs the conversion.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Executes the destructor for this type. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Visit the gc pointers owned by this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.