UniqueGc

Struct UniqueGc 

Source
pub struct UniqueGc<'b, T: ?Sized>(/* private fields */);
Expand description

A thin, garbage collected pointer type, which is guaranteed to be unique.

Implementations§

Source§

impl<'b, T> UniqueGc<'b, T>

Source

pub fn new(val: T, mt: &Mutation<'b>) -> UniqueGc<'b, T>
where T: Collect,

Allocates garbage collected memory on the heap and then places val into it.

This allocates regardless of if T is zero-sized.

§Examples
let five = UniqueGc::new(5, mt);
Source

pub fn new_uninit(mt: &Mutation<'b>) -> UniqueGc<'b, MaybeUninit<T>>

Constructs a new garbage collected pointer with uninitialized contents.

§Examples
let mut five = UniqueGc::<u32>::new_uninit(mt);

let five = unsafe {
    five.as_mut_ptr().write(5);

    five.assume_init()
};

assert_eq!(*five, 5);
Source

pub fn new_zeroed(mt: &Mutation<'b>) -> UniqueGc<'b, MaybeUninit<T>>

Constructs a new garbage collected pointer with uninitialized contents, with the memory being filled with 0 bytes.

See MaybeUninit::zeroed for examples of correct and incorrect usage of this method.

§Examples
let zero = UniqueGc::<u32>::new_zeroed(mt);
let zero = unsafe { zero.assume_init() };

assert_eq!(*zero, 0);
Source§

impl<'b, T> UniqueGc<'b, [T]>

Source

pub fn new_uninit_slice( len: usize, mt: &Mutation<'b>, ) -> UniqueGc<'b, [MaybeUninit<T>]>

Constructs a new garbage collected slice with uninitialized contents.

§Examples
let mut values = UniqueGc::<[u32]>::new_uninit_slice(3, mt);

let values = unsafe {
    values[0].as_mut_ptr().write(1);
    values[1].as_mut_ptr().write(2);
    values[2].as_mut_ptr().write(3);

    values.assume_init()
};

assert_eq!(*values, [1, 2, 3]);
Source

pub fn new_zeroed_slice( len: usize, mt: &Mutation<'b>, ) -> UniqueGc<'b, [MaybeUninit<T>]>

Constructs a new garbage collected slice with uninitialized contents, with the memory being filled with 0 bytes.

See MaybeUninit::zeroed for examples of correct and incorrect usage of this method.

§Examples
let values = UniqueGc::<[u32]>::new_zeroed_slice(3, mt);
let values = unsafe { values.assume_init() };

assert_eq!(*values, [0, 0, 0]);
Source§

impl<'b> UniqueGc<'b, str>

Source

pub fn from_str(s: &str, mt: &Mutation<'b>) -> UniqueGc<'b, str>

Constructs a new garbage collected string, copied from the passed value.

let s = UniqueGc::from_str("Hello, World!", mt);
assert_eq!(&*s, "Hello, World!");
Source§

impl<'b, T: Collect> UniqueGc<'b, MaybeUninit<T>>

Source

pub unsafe fn assume_init(self) -> UniqueGc<'b, T>

Converts to UniqueGc<'b, T>.

§Safety

As with MaybeUninit::assume_init, it is up to the caller to guarantee that the value really is in an initialized state. Calling this when the content is not yet fully initialized causes immediate undefined behaviour.

§Examples
let mut five = UniqueGc::<u32>::new_uninit(mt);

let five = unsafe {
    five.as_mut_ptr().write(5);

    five.assume_init()
};

assert_eq!(*five, 5);
Source

pub fn write(self, value: T) -> UniqueGc<'b, T>

Writes the value and converts to UniqueGc<'b, T>.

This method converts the pointer similarly to UniqueGc::assume_init, but writes value into it before the conversion, thus guaranteeing safety. In some scenarios use of this method may improve performance because the compiler may be able to optimize copying from stack.

Source§

impl<'b, T: Collect> UniqueGc<'b, [MaybeUninit<T>]>

Source

pub unsafe fn assume_init(self) -> UniqueGc<'b, [T]>

Converts to Gc<'b, [T]>.

§Safety

As with MaybeUninit::assume_init, it is up to the caller to guarantee that the values really are in an initialized state. Calling this when the content is not yet fully initialized causes immediate undefined behaviour.

§Examples
let mut values = UniqueGc::<[u32]>::new_uninit_slice(3, mt);

let values = unsafe {
    values[0].as_mut_ptr().write(1);
    values[1].as_mut_ptr().write(2);
    values[2].as_mut_ptr().write(3);

    values.assume_init()
};

assert_eq!(*values, [1, 2, 3]);
Source§

impl<'b, T: ?Sized> UniqueGc<'b, T>

Source

pub fn into_gc(this: Self) -> Gc<'b, T>

Converts the UniqueGc into a regular Gc.

This consumes the UniqueGc and returns a regular Gc which points to the same data as the UniqueGc.

§Examples
let gc: Gc<u32> = UniqueGc::into_gc(UniqueGc::new(5, mt));
Source

pub fn as_ptr(&self) -> *const T

Source

pub fn as_ptr_mut(&mut self) -> *mut T

Trait Implementations§

Source§

impl<T: ?Sized> Collect for UniqueGc<'_, T>

Source§

const NEEDS_TRACE: bool = true

Source§

fn trace(&self, c: &Collector)

Source§

impl<T: ?Sized + Debug> Debug for UniqueGc<'_, T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized> Deref for UniqueGc<'_, T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: ?Sized> DerefMut for UniqueGc<'_, T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T: ?Sized + Hash> Hash for UniqueGc<'_, T>

Source§

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

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

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

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

impl<T: ?Sized + Ord> Ord for UniqueGc<'_, T>

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: ?Sized + PartialEq> PartialEq for UniqueGc<'_, T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: ?Sized + PartialOrd> PartialOrd for UniqueGc<'_, T>

Source§

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

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: ?Sized + Eq> Eq for UniqueGc<'_, T>

Auto Trait Implementations§

§

impl<'b, T> Freeze for UniqueGc<'b, T>
where T: ?Sized,

§

impl<'b, T> !RefUnwindSafe for UniqueGc<'b, T>

§

impl<'b, T> !Send for UniqueGc<'b, T>

§

impl<'b, T> !Sync for UniqueGc<'b, T>

§

impl<'b, T> Unpin for UniqueGc<'b, T>
where T: Unpin + ?Sized,

§

impl<'b, T> !UnwindSafe for UniqueGc<'b, T>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.