pub trait Execute<I>: Component {
type Message;
type Effect;
type Error;
// Required method
fn execute(
&mut self,
instruction: &I,
message: Self::Message,
) -> Result<Self::Effect, Self::Error>;
}Expand description
Execute one instruction type with runtime-supplied input.
Available with the experimental typed-declarations feature. Each impl
chooses its message, result, and error types independently.
Implementing this trait alone does not declare dialect availability.
§Examples
use vihaco_runtime::{Component, Effects, Execute, NoMessage};
struct Add(i64);
struct Counter(i64);
impl Component for Counter {}
impl Execute<Add> for Counter {
type Message = NoMessage;
type Effect = Effects<i64>;
type Error = eyre::Report;
fn execute(&mut self, instruction: &Add, _: NoMessage) -> eyre::Result<Self::Effect> {
self.0 += instruction.0;
Ok(Effects::one(self.0))
}
}
let mut counter = Counter(1);
assert_eq!(counter.execute(&Add(2), NoMessage::new()).unwrap(), Effects::one(3));Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".