Struct gc::Gc[][src]

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.

Implementations

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

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

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);

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

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

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

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.

Examples

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.

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

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

fn as_ref(&self) -> &T[src]

Performs the conversion.

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

fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

fn clone(&self) -> Self[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

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

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

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

fn default() -> Self[src]

Returns the “default value” for a type. Read more

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

type Target = T

The resulting type after dereferencing.

fn deref(&self) -> &T[src]

Dereferences the value.

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

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

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

fn drop(&mut self)[src]

Executes the destructor for this type. Read more

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

fn finalize(&self)[src]

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

fn from(t: T) -> Self[src]

Performs the conversion.

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

fn hash<H: Hasher>(&self, state: &mut H)[src]

Feeds this value into the given Hasher. Read more

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

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

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

fn cmp(&self, other: &Self) -> Ordering[src]

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

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

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

Restrict a value to a certain interval. Read more

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

fn eq(&self, other: &Self) -> bool[src]

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

fn partial_cmp(&self, other: &Self) -> Option<Ordering>[src]

This method returns an ordering between self and other values if one exists. Read more

fn lt(&self, other: &Self) -> bool[src]

This method tests less than (for self and other) and is used by the < operator. Read more

fn le(&self, other: &Self) -> bool[src]

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

fn gt(&self, other: &Self) -> bool[src]

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

fn ge(&self, other: &Self) -> bool[src]

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

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

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter.

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

unsafe fn trace(&self)[src]

Marks all contained Gcs.

unsafe fn root(&self)[src]

Increments the root-count of all contained Gcs.

unsafe fn unroot(&self)[src]

Decrements the root-count of all contained Gcs.

fn finalize_glue(&self)[src]

Runs Finalize::finalize() on this object and all contained subobjects Read more

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

Auto Trait Implementations

impl<T> !RefUnwindSafe for Gc<T>

impl<T> !Send for Gc<T>

impl<T> !Sync for Gc<T>

impl<T: ?Sized> Unpin for Gc<T>

impl<T> !UnwindSafe for Gc<T>

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: !) -> T[src]

Performs the conversion.

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

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

recently added

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

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

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.