Skip to main content

StackValue

Trait StackValue 

Source
pub trait StackValue: Copy {
    type Storage;

    // Required methods
    fn from_storage(value: Self::Storage) -> Result<Self, Report>;
    fn into_storage(self) -> Self::Storage;

    // Provided methods
    fn pop_from(
        source: &mut impl PopStack<Self::Storage>,
    ) -> Result<Self, Report> { ... }
    fn push_to(self, destination: &mut impl PushStack<Self::Storage>) { ... }
}
Expand description

One copied logical stack value and its storage-representation conversions.

Separates the type a component computes with from the representation used to access program storage. A component can declare operands such as PopFromStack<(i64, f64)> and receive ordinary Rust values, while vihaco_stdlib::ExecutionState decides how to store them. A later optimized cursor can keep a floating-point value in a native cache without changing that component’s messages or effects. This trait is framework plumbing; ordinary component authors do not implement it or any stack access logic.

Conversions describe one logical value and have no stack access. The default readers/writers consume/produce exactly one value through those conversions. Custom items need not have a Word encoding. This trait does not select an output storage bank or require native float insertion to pass through Word.

Booleans decode zero as false and every nonzero word as true. Insertion normalizes them to 0 or 1; no canonical-input validation is performed.

Required Associated Types§

Source

type Storage

The value representation exchanged with the program’s storage machinery.

Built-in integers and booleans use [Word]; floats use their native types. For example, components compute with bool, while its storage access uses an encoded Word. An f64 stays an f64 at this interface: word-backed storage encodes its bits, while an optimized cursor can retain the native value and avoid conversions between instructions.

“Storage” describes this internal access representation, not a physical memory location, allocation, or bytecode encoding. It lets program storage evolve independently of the component-facing operand/result types. The selected runtime cache bank remains the storage implementation’s concern.

Required Methods§

Source

fn from_storage(value: Self::Storage) -> Result<Self, Report>

Convert one stored representation into a component-facing value.

§Errors

Returns any value-validation error required by a custom item. Built-in conversions accept every input, including truthy Boolean words.

Source

fn into_storage(self) -> Self::Storage

Convert this value into the representation accepted by program storage.

Provided Methods§

Source

fn pop_from(source: &mut impl PopStack<Self::Storage>) -> Result<Self, Report>

Consume one operand and convert it to this item.

§Errors

Propagates source-access or conversion errors. If conversion fails, the operand has already been consumed; previous pops are not rolled back.

Source

fn push_to(self, destination: &mut impl PushStack<Self::Storage>)

Convert and insert this item using the destination’s typed writer.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl StackValue for bool

Source§

impl StackValue for f32

Source§

impl StackValue for f64

Source§

impl StackValue for i32

Source§

impl StackValue for i64

Source§

impl StackValue for u32

Source§

impl StackValue for u64

Implementors§