2026-01-22 07:04:07 +00:00
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
}
|