Struct ProtectedVal

Source
pub struct ProtectedVal<'a> { /* private fields */ }
Expand description

Holds a value from the Vm that is guaranteed to not be garbage collected.

The underlying value is protected from garbage collection until ProtectedVal is dropped.

Implementations§

Source§

impl<'a> ProtectedVal<'a>

Source

pub fn new(vm: &'a mut Vm, v: Val<'a>) -> ProtectedVal<'a>

Create a new Val from an crate::val::UnsafeVal.

§Safety

v must be a valid from originating (and not garbage collected) from vm.

Source

pub fn split(&mut self) -> (&mut Vm, &Val<'_>)

Split the protected val into its Vm and Val.

Despite the split, the returned Val will still be safe from garbage collection.

Source

pub fn with<T>(&mut self, f: impl Fn(&mut Vm, &Val<'_>) -> T) -> T

Run function f on the Vm and Val and return the result. This is a convenient way of gaining mutable reference to the underlying vm.

Source§

impl<'a> ProtectedVal<'a>

Source

pub fn vm(&self) -> &Vm

Get a reference to the underlying Vm.

Source

pub fn map<T>(&mut self, f: impl Fn(&mut Vm, &ProtectedVal<'a>) -> T) -> T

Maps an Option<T> to Option<U> by applying a function to a contained value (if Some) or returns None (if None).

Source

pub fn try_str(&'a self) -> Result<&'a str, Val<'_>>

Try to get the string as a value or return its underlying value.

Source

pub fn try_custom<T: CustomType>( &self, ) -> Result<CustomValRef<'_, T>, CustomValError>

Try to get the custom value of type T or return its underlying value if self is not of type T.

Source

pub fn try_custom_mut<T: CustomType>( &self, ) -> Result<CustomValMut<'_, T>, CustomValError>

Returns the value as a custom type of T or Err if Self is not of the given custom value.

Source

pub fn get_mutable_box_ref(&self) -> Result<Val<'_>, Val<'a>>

Get the Val that the mutable box is pointing to or Err<Val> if self is not a mutable box.

Methods from Deref<Target = Val<'a>>§

Source

pub fn is_custom(&self) -> bool

Returns true if a custom value is held.

Source

pub fn try_custom<T: CustomType>( &self, vm: &'a Vm, ) -> Result<CustomValRef<'_, T>, CustomValError>

Returns the value as a custom type of T or None if Self is not of the given custom value.

Source

pub fn try_custom_mut<T: CustomType>( &self, vm: &'a Vm, ) -> Result<CustomValMut<'_, T>, CustomValError>

Returns the value as a custom type of T or None if Self is not of the given custom value.

Trait Implementations§

Source§

impl<'a> Debug for ProtectedVal<'a>

Source§

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

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

impl<'a> Deref for ProtectedVal<'a>

Source§

type Target = Val<'a>

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<'a> Display for ProtectedVal<'a>

Source§

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

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

impl<'a> Drop for ProtectedVal<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ProtectedVal<'a>

§

impl<'a> !RefUnwindSafe for ProtectedVal<'a>

§

impl<'a> Send for ProtectedVal<'a>

§

impl<'a> !Sync for ProtectedVal<'a>

§

impl<'a> Unpin for ProtectedVal<'a>

§

impl<'a> !UnwindSafe for ProtectedVal<'a>

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> ToCompactString for T
where T: Display,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.