act-zero-ext

Crates.ioact-zero-ext
lib.rsact-zero-ext
version0.2.0
created_at2025-07-08 15:56:25.655213+00
updated_at2025-09-24 15:25:01.999274+00
descriptionMacros for act-zero
homepage
repositoryhttps://github.com/praveen-reddy/act-zero-ext
max_upload_size
id1743092
size13,316
Praveen Perera (praveenperera)

documentation

https://docs.rs/act-zero-ext

README

act-zero-ext

Extention macros for act-zero

IntoActorResult Usage

Will wrap a function that returns a Result<T,E> into a function that returns a ActorResult<Result<T, E>>. Also works with Option<T> and returns ActorResult<Option<T>>.

Example:

pub struct App {}

impl App {
    #[act_zero_ext::into_actor_result]
    async fn hello(&self, name: String) -> Result<String, Box<dyn std::error::Error>> {
        Ok(format!("Hello, {}!", name))
    }
}

Will be converted to:

pub struct App {}

impl App {
    pub async fn hello(&self, name: String) -> ActorResult<Result<String, Box<dyn std::error::Error>>> {
        let result = self.do_hello(name).await;
        Produces::Ok(result)
    }

    async fn do_hello(&self, name: String) -> Result<String, Box<dyn std::error::Error>> {
        Ok(format!("Hello, {}!", name))
    }
}

Option Example

pub struct App {}

impl App {
    #[act_zero_ext::into_actor_result]
    async fn find_user(&self, id: u64) -> Option<String> {
        if id > 0 {
            Some(format!("User {}", id))
        } else {
            None
        }
    }
}

Will be converted to:

pub struct App {}

impl App {
    pub async fn find_user(&self, id: u64) -> ActorResult<Option<String>> {
        let result = self.do_find_user(id).await;
        Produces::ok(result)
    }

    async fn do_find_user(&self, id: u64) -> Option<String> {
        if id > 0 {
            Some(format!("User {}", id))
        } else {
            None
        }
    }
}
Commit count: 0

cargo fmt