[][src]Struct gc::Gc

pub struct Gc<T: Trace + ?Sized + 'static> { /* fields omitted */ }

A garbage-collected pointer type over an immutable value.

See the module level documentation for more details.


impl<T: Trace> Gc<T>[src]

pub fn new(value: T) -> Self[src]

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


This method could trigger a garbage collection.


use gc::Gc;

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

impl<T: Trace + ?Sized> Gc<T>[src]

pub fn into_raw(this: Self) -> *const T[src]

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.


use gc::Gc;

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

pub unsafe fn from_raw(ptr: *const T) -> Self[src]

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.


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

impl<T: Trace + ?Sized> Finalize for Gc<T>[src]

fn finalize(&self)[src]

impl<T: Trace + ?Sized> Trace for Gc<T>[src]

impl<T: Trace + ?Sized> Drop for Gc<T>[src]

impl<T: Trace + ?Sized + PartialEq> PartialEq<Gc<T>> for Gc<T>[src]

impl<T: Trace + Default> Default for Gc<T>[src]

impl<T: Trace + ?Sized> Clone for Gc<T>[src]

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

impl<T: Trace + ?Sized + Ord> Ord for Gc<T>[src]

fn max(self, other: Self) -> Self

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

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

Restrict a value to a certain interval. Read more

impl<T: Trace> From<T> for Gc<T>[src]

impl<T: Trace + ?Sized + Eq> Eq for Gc<T>[src]

impl<T: Trace + ?Sized + PartialOrd> PartialOrd<Gc<T>> for Gc<T>[src]

impl<T: Trace + ?Sized> Deref for Gc<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T: Trace + ?Sized + Display> Display for Gc<T>[src]

impl<T: Trace + ?Sized + Debug> Debug for Gc<T>[src]

impl<T: Trace + ?Sized + Hash> Hash for Gc<T>[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher

Feeds a slice of this type into the given [Hasher]. Read more

impl<T: Trace> Pointer for Gc<T>[src]

Auto Trait Implementations

impl<T> !Send for Gc<T>

impl<T> !Sync for Gc<T>

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

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

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

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