oricalchum_derive

Crates.iooricalchum_derive
lib.rsoricalchum_derive
version0.1.1
sourcesrc
created_at2024-10-13 18:41:10.26175
updated_at2024-10-14 16:26:17.010726
descriptionProcedural macros for oricalchum
homepage
repositoryhttps://github.com/Jordan-Dimitrov/Oricalchum
max_upload_size
id1407573
size4,452
(Jordan-Dimitrov)

documentation

README

oricalchum_derive

Procedural macros for oricalchum

Usage

use oricalchum::TrackActor;
use async_trait::async_trait;
use oricalchum::{Actor, ActorSystem, Context};
use oricalchum_derive::TrackActor;

pub enum Test {
    PrintOk(String),
    PrintErr(String, i32),
}

#[derive(TrackActor)]
pub struct TestActor {
    pub name: String,
    pub value: String
}

#[async_trait]
impl Actor for TestActor {
    type Msg = Test;

    async fn handle(&mut self, msg: Self::Msg, ctx: &mut Context<Self>) {
        self.log();
        match msg {
            Test::PrintOk(text) => {
                println!("{} {}", self.name, text);
            }
            Test::PrintErr(text, b) => {
                println!("{} {}", text, b);
            }
        }
    }
}

#[tokio::main]
async fn main() {
    let actor1 = TestActor { name: String::from("actor1"), value: String::from("test1") };

    let addr1 = ActorSystem::spawn_actor(actor1, 16).await;

    addr1.send(Test::PrintOk(String::from("Ok"))).await;
}
Commit count: 22

cargo fmt