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.
34 lines
716 B
Rust
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();
|
|
|
|
}
|