1
0
mirror of https://github.com/actix/actix synced 2024-12-02 18:02:23 +01:00
actix/actix-derive
2024-02-01 04:38:28 +00:00
..
src docs: prefer shorter rtype where possible 2024-02-01 04:38:28 +00:00
tests Added path type as a possible value for rtype result (#575) 2024-02-01 04:13:00 +00:00
Cargo.toml chore(actix_derive): prepare release 0.6.1 2023-09-10 02:43:52 +01:00
CHANGES.md chore(actix_derive): prepare release 0.6.1 2023-09-10 02:43:52 +01:00
LICENSE-APACHE move derive crate into workspace (#424) 2020-09-21 23:32:59 +01:00
LICENSE-MIT move derive crate into workspace (#424) 2020-09-21 23:32:59 +01:00
README.md docs: prefer shorter rtype where possible 2024-02-01 04:38:28 +00:00

actix-derive

Derive macros for actix actors.

crates.io Documentation Minimum Supported Rust Version License Dependency Status

Usage

use actix_derive::{Message, MessageResponse};

#[derive(MessageResponse)]
struct Added(usize);

#[derive(Message)]
#[rtype(Added)]
struct Sum(usize, usize);

fn main() {}

This code expands into following code:

use actix::{Actor, Context, Handler, System};
use actix_derive::{Message, MessageResponse};

#[derive(MessageResponse)]
struct Added(usize);

#[derive(Message)]
#[rtype(Added)]
struct Sum(usize, usize);

#[derive(Default)]
struct Adder;

impl Actor for Adder {
    type Context = Context<Self>;
}

impl Handler<Sum> for Adder {
    type Result = <Sum as actix::Message>::Result;
    fn handle(&mut self, msg: Sum, _: &mut Self::Context) -> Added {
        Added(msg.0 + msg.1)
    }
}

fn main() {}

License

This project is licensed under either of

at your option.