[][src]Struct glsp::Gc

pub struct Gc<T>(_, _)
    T: Allocate

A weak pointer onto the garbage-collected heap.

Gc's API is very similar to std::rc::Weak. You can construct a Gc by calling Root::downgrade. A Gc can't be dereferenced; instead, you should promote it to a Root by calling Gc::upgrade.

You should almost always use Root rather than Gc.

The only exception is RData. If you store a Root within an RData, it will cause a memory leak. If you need to construct an RData which stores a pointer to another heap-allocated object, you should:

The last two steps are necessary to prevent the pointed-to object from being deallocated.

See also GcVal (a Val which stores Gc pointers rather than Root pointers), and RGc (a strongly-typed alternative to Gc<RData>).

struct Collider {
	bounds: Rect,
	obj: Gc<Obj>

impl Collider {
	fn trace(&self, visitor: &mut GcVisitor) {

fn setup() {

fn new_collider(obj: Root<Obj>) -> GResult<Root<RData>> {
	let collider = Collider {
		bounds: obj.get("bounds")?,
		obj: obj.downgrade()



impl<T> Gc<T> where
    T: Allocate, 

pub fn upgrade(&self) -> Option<Root<T>>[src]

Attempts to construct a strong pointer from this weak pointer.

Returns None if the pointed-to object has been deallocated by the garbage collector. To prevent this, use glsp::write_barrier and RClassBuilder::trace.

pub fn ptr_eq(gc0: &Gc<T>, gc1: &Gc<T>) -> bool[src]

Returns true if both Gcs point to the same heap-allocated object.

Trait Implementations

impl<T> Clone for Gc<T> where
    T: Allocate, 

impl<T> Drop for Gc<T> where
    T: Allocate, 

Auto Trait Implementations

impl<T> RefUnwindSafe for Gc<T> where
    T: RefUnwindSafe

impl<T> !Send for Gc<T>[src]

impl<T> !Sync for Gc<T>[src]

impl<T> Unpin for Gc<T>[src]

impl<T> UnwindSafe for Gc<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> Erased for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T> IntoElement<Slot> for T where
    T: IntoVal

impl<T> IntoVal for T where
    T: StaticMarker, 

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.