Skip to main content

MutateValue

Struct MutateValue 

Source
pub struct MutateValue<'a, T = Any> { /* private fields */ }
Expand description

A callback value carrying the engine’s in-place permission.

Unlike an owning typed argument, this handle does not increment the reference count. Borrow through it to inspect the node, then consume it in default_maybe_inplace_mutate to continue recursion. A surviving owning alias still forces copying. Node borrows come from this handle, not from the callback context, so the handle can safely be passed to another context. T selects the callback’s matched FFI type; Any matches every value.

A node borrow cannot survive consumption of the handle:

ⓘ
use tvm_ffi::{MutateContext, MutateValue};
fn invalid(value: MutateValue<'_>, ctx: &mut MutateContext<'_>) {
    let node = value.as_node::<tvm_ffi::collections::array::ArrayObj>().unwrap();
    ctx.default_maybe_inplace_mutate(value).unwrap();
    println!("{}", node.size);
}

Moving the handle into a nested callback cannot bypass that borrow:

ⓘ
use std::cell::RefCell;
use tvm_ffi::{structural_mutate, MutateContext, MutateValue};
fn invalid(value: MutateValue<'_>) {
    let node = value.as_node::<tvm_ffi::collections::array::ArrayObj>().unwrap();
    let pending = RefCell::new(Some(value));
    structural_mutate(true, |_: bool, inner: &mut MutateContext<'_>| {
        inner.default_maybe_inplace_mutate(pending.borrow_mut().take().unwrap())
    }).unwrap();
    println!("{}", node.size);
}

Implementations§

Source§

impl<'a> MutateValue<'a>

Source

pub fn borrowed(value: &'a StructuralView) -> Self

Wrap a borrowed value without granting in-place permission.

Source§

impl<'a, T> MutateValue<'a, T>

Source

pub fn inplace_mode(&self) -> InplaceMode

Permission established before callback arguments acquire ownership.

Source

pub fn as_value(&self) -> &StructuralView

Borrow the current value. The borrow must end before default mutation.

Source

pub fn try_cast<U: ContainerElement>(self) -> Result<MutateValue<'a, U>, Self>

Narrow the matched type without acquiring an owning reference.

Source

pub fn into_untyped(self) -> MutateValue<'a>

Erase the matched type while preserving the engine-issued permission.

Methods from Deref<Target = StructuralView>§

Source

pub fn to_owned(&self) -> Any

Copy this borrowed value into an owning Any.

Source

pub fn cast<R: AnyCompatible>(&self) -> Option<R>

Convert the value into an owned typed handle.

Source

pub fn type_index(&self) -> i32

Runtime type index stored in this value.

Source

pub fn as_node<N: ObjectCore>(&self) -> Option<&N>

Borrow the value as node type N if it is an instance of that type.

Trait Implementations§

Source§

impl<T> Deref for MutateValue<'_, T>

Source§

type Target = StructuralView

The resulting type after dereferencing.
Source§

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

Dereferences the value.

Auto Trait Implementations§

§

impl<'a, T = Any> !Send for MutateValue<'a, T>

§

impl<'a, T = Any> !Sync for MutateValue<'a, T>

§

impl<'a, T> Freeze for MutateValue<'a, T>

§

impl<'a, T> RefUnwindSafe for MutateValue<'a, T>

§

impl<'a, T> Unpin for MutateValue<'a, T>

§

impl<'a, T> UnsafeUnpin for MutateValue<'a, T>

§

impl<'a, T> UnwindSafe for MutateValue<'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<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.