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>
impl<'b, T> UniqueGc<'b, T>
Sourcepub fn new(val: T, mt: &Mutation<'b>) -> UniqueGc<'b, T>where
T: Collect,
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);Sourcepub fn new_uninit(mt: &Mutation<'b>) -> UniqueGc<'b, MaybeUninit<T>>
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);Sourcepub fn new_zeroed(mt: &Mutation<'b>) -> UniqueGc<'b, MaybeUninit<T>>
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]>
impl<'b, T> UniqueGc<'b, [T]>
Sourcepub fn new_uninit_slice(
len: usize,
mt: &Mutation<'b>,
) -> UniqueGc<'b, [MaybeUninit<T>]>
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]);Sourcepub fn new_zeroed_slice(
len: usize,
mt: &Mutation<'b>,
) -> UniqueGc<'b, [MaybeUninit<T>]>
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, T: Collect> UniqueGc<'b, MaybeUninit<T>>
impl<'b, T: Collect> UniqueGc<'b, MaybeUninit<T>>
Sourcepub unsafe fn assume_init(self) -> UniqueGc<'b, T>
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);Sourcepub fn write(self, value: T) -> UniqueGc<'b, T>
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>]>
impl<'b, T: Collect> UniqueGc<'b, [MaybeUninit<T>]>
Sourcepub unsafe fn assume_init(self) -> UniqueGc<'b, [T]>
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]);