Struct boa_gc::Gc

source · []
pub struct Gc<T>where
    T: 'static + Trace + ?Sized,
{ /* private fields */ }
Expand description

A garbage-collected pointer type over an immutable value.

See the module level documentation for more details.

Implementations

Constructs a new Gc<T> with the given value.

Collection

This method could trigger a garbage collection.

Examples
use gc::Gc;

let five = Gc::new(5);
assert_eq!(*five, 5);

Returns true if the two Gcs point to the same allocation.

Consumes the Gc, returning the wrapped pointer.

To avoid a memory leak, the pointer must be converted back into a Gc using Gc::from_raw.

Examples
use gc::Gc;

let x = Gc::new(22);
let x_ptr = Gc::into_raw(x);
assert_eq!(unsafe { *x_ptr }, 22);

Constructs an Gc from a raw pointer.

The raw pointer must have been previously returned by a call to a Gc::into_raw.

This function is unsafe because improper use may lead to memory problems. For example, a use-after-free will occur if the function is called twice on the same raw pointer.

Examples
use gc::Gc;

let x = Gc::new(22);
let x_ptr = Gc::into_raw(x);

unsafe {
    // Convert back to an `Gc` to prevent leak.
    let x = Gc::from_raw(x_ptr);
    assert_eq!(*x, 22);

    // Further calls to `Gc::from_raw(x_ptr)` would be memory unsafe.
}

// The memory can be freed at any time after `x` went out of scope above
// (when the collector is run), which would result in `x_ptr` dangling!

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.
Immutably borrows from an owned value. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
The resulting type after dereferencing.
Dereferences the value.
Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. 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 !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
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
Formats the value using the given formatter.
Marks all contained Gcs.
Increments the root-count of all contained Gcs.
Decrements the root-count of all contained Gcs.
Runs Finalize::finalize() on this object and all contained subobjects 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
Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. 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.