swactor/examples/hello.rs
Zachery Aaron Shores-Chmielewski 08b241481f stash: rewrite wip
We have a basic ring buffer for dealing with concurrent message exchange. Currently
in the middle of reifying the traits, types and structs needed for the `hello.rs`
example of the simple `Hello, World!` greeter type actor.
2026-01-22 14:04:07 +07:00

34 lines
716 B
Rust

use bytemuck::{Pod, Zeroable};
use swactor::{ActorAddress, ActorInterface, Message, Runtime};
#[repr(C)]
#[derive(Pod, Zeroable)]
struct Greeter {
pub num_greeted: usize,
}
#[derive(Clone)]
struct GreetMessage {
name: String,
addr: ActorAddress,
}
impl Message for GreetMessage {}
impl ActorInterface<GreetMessage> for Greeter {
fn handle(&mut self, ctx: &Runtime, msg: GreetMessage) {
let res = GreetResponse(format!("Hello, {}!", msg.name));
if let Err(_) = ctx.send(res, msg.addr) {
// no error handling
}
}
}
#[derive(Debug, Default, Clone)]
struct GreetResponse(String);
impl Message for GreetResponse {}
fn main() {
let rt = Runtime::new();
}