speare_macro

Crates.iospeare_macro
lib.rsspeare_macro
version0.0.8
sourcesrc
created_at2023-10-09 22:25:27.194523
updated_at2024-01-09 08:55:21.23402
descriptionmacro to make speare crate easier to use
homepagehttps://github.com/vmenge/speare
repositoryhttps://github.com/vmenge/speare
max_upload_size
id998562
size13,256
vmenge (vmenge)

documentation

README

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)
    }
}
Commit count: 54

cargo fmt