Skip to main content

component

Attribute Macro component 

#[component]
Expand description

Declare a component’s complete dialect capabilities.

Available with typed-declarations. Apply to any struct with exactly one nonempty #[instructions { dialect_paths, ... }] helper. Paths name whole dialect modules, including imported aliases. Implement Execute for every instruction in every listed dialect under the struct’s original bounds. Each implementation may choose its own message, effect, and error types. The declaration preserves the struct and implements Component without requiring an aggregate instruction set. Canonical instruction overlaps are rejected even on unused generic components. #[vihaco(crate = path)] selects an explicit framework root in the struct’s authored scope.

use vihaco_runtime::{component, dialect, Execute, NoMessage};
#[dialect]
mod control {
    #[instruction]
    pub struct Halt;
}
#[component]
#[instructions { control }]
struct Cpu<T = u8>(T);
impl<T> Execute<control::Halt> for Cpu<T> {
    type Message = NoMessage;
    type Effect = ();
    type Error = std::convert::Infallible;
    fn execute(&mut self, _: &control::Halt, _: NoMessage) -> Result<(), Self::Error> {
        Ok(())
    }
}

Declare complete dialect support on a struct with #[instructions { dialects }].