pub struct UnboxedValueGuard<'a, T> { /* private fields */ }

Implementations§

source§

impl<'a, T> UnboxedValueGuard<'a, T>

source

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.

source

pub fn as_inner_ref(&self) -> &T

Get a shared reference to the inner T.

source

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.

source

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.

Trait Implementations§

source§

impl<'a, T> Debug for UnboxedValueGuard<'a, T>
where T: Debug,

source§

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

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

impl<'a> Deref for UnboxedValueGuard<'a, Array>

§

type Target = Array

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<'a, T> Deref for UnboxedValueGuard<'a, HeapAllocated<T>>

§

type Target = T

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<'a, T> Deref for UnboxedValueGuard<'a, Immediate<T>>

§

type Target = T

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<'a> Deref for UnboxedValueGuard<'a, String>

§

type Target = String

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<'a, T> DerefMut for UnboxedValueGuard<'a, HeapAllocated<T>>

source§

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

Mutably dereferences the value.
source§

impl<'a, T> DerefMut for UnboxedValueGuard<'a, Immediate<T>>

source§

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

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<'a, T> Freeze for UnboxedValueGuard<'a, T>
where T: Freeze,

§

impl<'a, T> RefUnwindSafe for UnboxedValueGuard<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for UnboxedValueGuard<'a, T>
where T: Send,

§

impl<'a, T> Sync for UnboxedValueGuard<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for UnboxedValueGuard<'a, T>
where T: Unpin,

§

impl<'a, T> !UnwindSafe for UnboxedValueGuard<'a, 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<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.