Expand description
A garbage-collected pointer type over an immutable value.
See the module level documentation for more details.
Implementations
sourceimpl<T> Gc<T>where
T: Trace,
impl<T> Gc<T>where
T: Trace,
sourcepub fn new(value: T) -> Gc<T>
pub fn new(value: T) -> Gc<T>
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);
sourceimpl<T> Gc<T>where
T: Trace + ?Sized,
impl<T> Gc<T>where
T: Trace + ?Sized,
sourcepub fn into_raw(this: Gc<T>) -> *const T
pub fn into_raw(this: Gc<T>) -> *const T
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);
sourcepub unsafe fn from_raw(ptr: *const T) -> Gc<T>
pub unsafe fn from_raw(ptr: *const T) -> Gc<T>
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
sourceimpl<T> Ord for Gc<T>where
T: Trace + Ord + ?Sized,
impl<T> Ord for Gc<T>where
T: Trace + Ord + ?Sized,
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<T> PartialEq<Gc<T>> for Gc<T>where
T: Trace + PartialEq<T> + ?Sized,
impl<T> PartialEq<Gc<T>> for Gc<T>where
T: Trace + PartialEq<T> + ?Sized,
sourceimpl<T> PartialOrd<Gc<T>> for Gc<T>where
T: Trace + PartialOrd<T> + ?Sized,
impl<T> PartialOrd<Gc<T>> for Gc<T>where
T: Trace + PartialOrd<T> + ?Sized,
sourceimpl<T> Trace for Gc<T>where
T: Trace + ?Sized,
impl<T> Trace for Gc<T>where
T: Trace + ?Sized,
sourcefn finalize_glue(&self)
fn finalize_glue(&self)
Runs Finalize::finalize() on this object and all
contained subobjects Read more
impl<T> Eq for Gc<T>where
T: Trace + Eq + ?Sized,
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more