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>
impl<'a> MutateValue<'a>
Sourcepub fn borrowed(value: &'a StructuralView) -> Self
pub fn borrowed(value: &'a StructuralView) -> Self
Wrap a borrowed value without granting in-place permission.
Source§impl<'a, T> MutateValue<'a, T>
impl<'a, T> MutateValue<'a, T>
Sourcepub fn inplace_mode(&self) -> InplaceMode
pub fn inplace_mode(&self) -> InplaceMode
Permission established before callback arguments acquire ownership.
Sourcepub fn as_value(&self) -> &StructuralView
pub fn as_value(&self) -> &StructuralView
Borrow the current value. The borrow must end before default mutation.
Sourcepub fn try_cast<U: ContainerElement>(self) -> Result<MutateValue<'a, U>, Self>
pub fn try_cast<U: ContainerElement>(self) -> Result<MutateValue<'a, U>, Self>
Narrow the matched type without acquiring an owning reference.
Sourcepub fn into_untyped(self) -> MutateValue<'a>
pub fn into_untyped(self) -> MutateValue<'a>
Erase the matched type while preserving the engine-issued permission.
Methods from Deref<Target = StructuralView>§
Sourcepub fn cast<R: AnyCompatible>(&self) -> Option<R>
pub fn cast<R: AnyCompatible>(&self) -> Option<R>
Convert the value into an owned typed handle.
Sourcepub fn type_index(&self) -> i32
pub fn type_index(&self) -> i32
Runtime type index stored in this value.
Sourcepub fn as_node<N: ObjectCore>(&self) -> Option<&N>
pub fn as_node<N: ObjectCore>(&self) -> Option<&N>
Borrow the value as node type N if it is an instance of that type.