[][src]Struct glsp::Gc

pub struct Gc<T>(_, _)
where
    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) {
		visitor.visit(&self.obj);
	}
}

fn setup() {
	RClassBuilder::<Collider>::new()
		.trace(Collider::trace)
		.build();
}

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

	Ok(glsp::rdata(collider))
}

Implementations

impl<T> Gc<T> where
    T: Allocate, 
[src]

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, 
[src]

impl<T> Drop for Gc<T> where
    T: Allocate, 
[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Gc<T> where
    T: RefUnwindSafe
[src]

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
[src]

Blanket Implementations

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

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Erased for T

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoElement<Slot> for T where
    T: IntoVal
[src]

impl<T> IntoVal for T where
    T: StaticMarker, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.