Skip to main content

Dismantle

Trait Dismantle 

Source
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§

Source

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 Error

Available on crate feature std only.
Source§

fn dismantle(&mut self, out: &mut Handover<'_>)

Source§

impl Dismantle for Error

Available on crate feature anyhow only.
Source§

fn dismantle(&mut self, out: &mut Handover<'_>)

Source§

impl Dismantle for Error

Source§

fn dismantle(&mut self, out: &mut Handover<'_>)

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.

Source§

fn dismantle(&mut self, out: &mut Handover<'_>)

Source§

impl Dismantle for ParseCharError

Source§

fn dismantle(&mut self, out: &mut Handover<'_>)

Source§

impl Dismantle for ParseFloatError

Source§

fn dismantle(&mut self, out: &mut Handover<'_>)

Source§

impl Dismantle for ParseIntError

Source§

fn dismantle(&mut self, out: &mut Handover<'_>)

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.

Source§

fn dismantle(&mut self, out: &mut Handover<'_>)

Source§

impl Dismantle for Utf8Error

Source§

fn dismantle(&mut self, out: &mut Handover<'_>)

Implementors§

Source§

impl Dismantle for Bencher

Source§

impl Dismantle for Bytes

Source§

impl Dismantle for ControlFlow

Source§

impl Dismantle for Format

Source§

impl Dismantle for Formatter

Source§

impl Dismantle for FromUtf8Error

Source§

impl Dismantle for Function

A closure holds the environment it captured, so a closure which captured another one nests just like a container does.

Source§

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.

Source§

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.

Source§

impl Dismantle for GeneratorState

Source§

impl Dismantle for Hasher

Source§

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.

Source§

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.

Source§

impl Dismantle for Range

Source§

impl Dismantle for RangeFrom

Source§

impl Dismantle for RangeFull

Source§

impl Dismantle for RangeInclusive

Source§

impl Dismantle for RangeTo

Source§

impl Dismantle for RangeToInclusive

Source§

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.

Source§

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.

Source§

impl Dismantle for String

Source§

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.

Source§

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.