actix / actix-derive

[ARCHIVED] development moved into main actix repo

Home Page:https://github.com/actix/actix

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

actix-derive Build Status crates.io

Actix is a rust actor framework.


Features

  • actix-derive adds support for Rust Custom Derive / Macros 1.1 to actix

Usage

use actix_derive::{Message, MessageResponse};

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

#[derive(Message)]
#[rtype(result = "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(result = "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.

About

[ARCHIVED] development moved into main actix repo

https://github.com/actix/actix

License:Apache License 2.0


Languages

Language:Rust 100.0%