pub trait Dismantle {
// Required method
fn dismantle(&mut self, out: &mut Handover<'_>);
}Expand description
How a value stored in the virtual machine hands over the values it is made of, so that a graph of them is taken apart without recursing into it.
Every type which implements Any implements this as well, and the Any
derive writes it: a type which is not made of values hands nothing over and
is dropped in place, which is what the derive writes unless it is told
otherwise.
A type which does hold Values has to hand them over, since a script can
nest such a type inside itself without any bound - v = [v] in a loop - and
dropping what that builds costs a native frame per level otherwise, which
exhausts the call stack. Mark the fields which hold them:
use rune::Any;
use rune::Value;
#[derive(Any)]
struct Pair {
#[rune(dismantle)]
first: Value,
#[rune(dismantle)]
second: Value,
count: u32,
}Anything the derive cannot write - a collection, an iterator which holds what
it walks through a guard - is written by hand instead, by declaring the type
#[rune(dismantle)] and implementing this trait for it.
Required Methods§
Sourcefn dismantle(&mut self, out: &mut Handover<'_>)
fn dismantle(&mut self, out: &mut Handover<'_>)
Hand over every value this is made of, leaving nothing behind which is itself made of values.
Whatever is left is dropped once this returns, so a value which is not handed over is dropped where it is - which costs a native frame for every level a script nests it.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl Dismantle for Option<Value>
A value which may or may not be there is made of the one it holds, and a
script can nest one inside another - a = Some(a) in a loop.
impl Dismantle for Option<Value>
A value which may or may not be there is made of the one it holds, and a
script can nest one inside another - a = Some(a) in a loop.
Source§impl Dismantle for Result<Value, Value>
Either outcome is made of the value it holds, and a script can nest one
inside another - a = Ok(a) in a loop.
impl Dismantle for Result<Value, Value>
Either outcome is made of the value it holds, and a script can nest one
inside another - a = Ok(a) in a loop.
Implementors§
impl Dismantle for Bencher
impl Dismantle for Bytes
impl Dismantle for ControlFlow
impl Dismantle for Format
impl Dismantle for Formatter
impl Dismantle for FromUtf8Error
impl Dismantle for Function
A closure holds the environment it captured, so a closure which captured another one nests just like a container does.
impl Dismantle for Future
A future which was never awaited still holds everything the execution it drives was working over, so futures nest just like a container does.
impl Dismantle for Generator
A suspended generator holds every value its machine was working over, so a generator which captured another one nests just like a container does.
impl Dismantle for GeneratorState
impl Dismantle for Hasher
impl Dismantle for Object
An object is made of the values put into it, and a script can nest one inside another without any bound, so it hands over what it is made of rather than being dropped in place.
impl Dismantle for OwnedTuple
A tuple is made of the values put into it, and a script can nest one inside another without any bound, so it hands over what it is made of rather than being dropped in place.
impl Dismantle for Range
impl Dismantle for RangeFrom
impl Dismantle for RangeFull
impl Dismantle for RangeInclusive
impl Dismantle for RangeTo
impl Dismantle for RangeToInclusive
impl Dismantle for Stack
A stack holds the values a machine is working over, so a machine which is suspended - a generator or a stream - holds a graph of values through it.
impl Dismantle for Stream
A suspended stream holds every value its machine was working over, so a stream which captured another one nests just like a container does.
impl Dismantle for String
impl Dismantle for Value
A value is the leaf of the walk: it is handed over as it is, unless it cannot contain other values, in which case there is nothing to hand over.
This is what makes handing a field over the same call whatever the field holds, which is what the derive writes.
impl Dismantle for Vec
A vector is made of the values put into it, and a script can nest one inside another without any bound, so it hands over what it is made of rather than being dropped in place.