8 releases

0.0.8 Jan 9, 2024
0.0.7 Nov 13, 2023
0.0.1 Oct 9, 2023

#1285 in Procedural macros

Download history 5/week @ 2024-02-22 3/week @ 2024-02-29 139/week @ 2024-03-21 4/week @ 2024-03-28 1/week @ 2024-04-04

696 downloads per month

MIT license

14KB
235 lines

DEPRECATED

speare_macro

This crate's sole purpose is to reduce the amount of boilerplate needed when working with the speare crate.

With it, we can write

pub struct Foo;

#[process]
impl Foo {
    #[handler]
    async fn bar(&mut self, msg: u64, ctx: &Ctx<Self>) -> Result<String, ()> {
        Ok(format!("{msg}"))
    }

    #[handler]
    async fn baz(&mut self, msg: String, ctx: &Ctx<Self>) -> Result<String, ()> {
        Ok(msg)
    }
}

instead of

pub struct Foo;

impl Process for Foo {
    type Error = ();
}

#[async_trait]
impl Handler<u64> for Foo {
    type Ok = String;
    type Err = ();

    async fn handle(&mut self, msg: u64, ctx: &Ctx<Self>) -> Result<String, ()> {
        Ok(format!("{msg}"))
    }
}

#[async_trait]
impl Handler<String> for Foo {
    type Ok = String;
    type Err = ();

    async fn handle(&mut self, msg: u64, ctx: &Ctx<Self>) -> Result<String, ()> {
        Ok(msg)
    }
}

Dependencies

~325–790KB
~19K SLoC