pub struct UnboxedValueGuard<'a, T> { /* private fields */ }
Implementations§
Source§impl<'a, T> UnboxedValueGuard<'a, T>
impl<'a, T> UnboxedValueGuard<'a, T>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Construct a new guard around the given T
.
UnboxedValueGuard
allows passing around a &mut
reference without
dropping the T
when returning control to mruby C code. This is
desirable because the T
is owned by the mruby heap until the mruby
garbage collector frees the mrb_value
that holds it.
Sourcepub fn as_inner_ref(&self) -> &T
pub fn as_inner_ref(&self) -> &T
Get a shared reference to the inner T
.
Sourcepub unsafe fn as_inner_mut(&mut self) -> &mut T
pub unsafe fn as_inner_mut(&mut self) -> &mut T
Get a unique reference to the inner T
.
§Safety
Callers must ensure the raw parts stored in the source mrb_value
are
not invalidated OR that the raw parts are repacked before an mruby
allocation occurs.
Sourcepub unsafe fn take(self) -> T
pub unsafe fn take(self) -> T
Take the inner T
out of the guard.
§Safety
Callers must ensure that T
is not dropped. Once T
is taken out of
the guard, it must ultimately be passed to ManuallyDrop
before it is
dropped.
An example of safe usage is calling taking an Array
out of the guard
and then immediately calling Array::into_raw_parts
on the returned
value.