Skip to main content

BuildMessage

Trait BuildMessage 

Source
pub trait BuildMessage<F, I, Context: ?Sized = (), M = <<Self as Field<F>>::Child as Execute<I>>::Message>: Field<F>
where Self::Child: Execute<I, Message = M>,
{ // Required method fn build_message(&mut self, instruction: &I, context: &Context) -> Result<M>; }
Expand description

Build execution input for one composite field route and instruction type.

Available with the experimental typed-declarations feature. The selected child’s Execute<I> implementation determines the message type. The M parameter defaults to that associated type. Context defaults to (); runners can instead supply immutable runtime data such as a borrowed module. Consumers can write C: BuildMessage<F, I, Context>.

Composite authors implement this trait to choose how their specific machine builds each message. The body of build_message can construct the input directly or explicitly delegate to a message’s ReusableMessageRecipe. Standard messages, including NoMessage and typed stack inputs, provide recipes but do not automatically implement this trait for a composite.

Specify M explicitly in those implementations, such as BuildMessage<F, Call, (), FunctionInfo>. Distinct explicit message types can separate generic builders for different input shapes. The equality bound requires M to match the child’s execution message; it cannot select a different one.

A crate::Step implementation can use this optional helper to separate message construction from execution and effect handling. Implementing this trait neither executes an instruction nor supplies a Step implementation.

use vihaco_runtime::{BuildMessage, Execute, Field};

fn prepare<C, F, I>(
    composite: &mut C,
    instruction: &I,
) -> vihaco_runtime::eyre::Result<<C::Child as Execute<I>>::Message>
where
    C: BuildMessage<F, I>,
    C::Child: Execute<I>,
{
    composite.build_message(instruction, &())
}

Required Methods§

Source

fn build_message(&mut self, instruction: &I, context: &Context) -> Result<M>

Resolve and validate the input needed to execute instruction.

The builder may mutate the composite, for example by consuming stack operands. Mutations made before an error are retained.

§Errors

Returns message-preparation failures, such as invalid program references or missing runtime inputs. Callers can propagate the original report through crate::Step before invoking the child.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§