Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make msg! macro to return value #110

Closed
onsails opened this issue Dec 2, 2019 · 0 comments · Fixed by #111
Closed

Make msg! macro to return value #110

onsails opened this issue Dec 2, 2019 · 0 comments · Fixed by #111
Assignees
Labels
bug Something isn't working

Comments

@onsails
Copy link
Member

onsails commented Dec 2, 2019

msg! macro returning value is useful for constructing async interfaces to actors:

struct AsyncFoo {
    child: ChildRef,
}

impl AsyncFoo {
    pub async fn open_bar(&self, open_bar: &OpenBar) -> Result<BarId, Error> {
        let answer = self
            .child
            .ask(open_bar)
            .expect("Failed to send message");

        msg! { answer.await.expect("Failed to receive answer"),
            msg: Result<BarId, Error> => {
                msg;
            };
            _: _ => Err(format_err!("wrong answer"));
        }
    }
}

Currently, this code leads to compilation error, compiler sees () return type but expects Result<BarId, Error>.

Same problem happens with explicit return inside a macro:

struct AsyncFoo {
    child: ChildRef,
}

impl AsyncFoo {
    pub async fn open_bar(&self, open_bar: &OpenBar) -> Result<BarId, Error> {
        let answer = self
            .child
            .ask(open_bar)
            .expect("Failed to send message");

        msg! { answer.await.expect("Failed to receive answer"),
            msg: Result<BarId, Error> => {
                return msg;
            };
            _: _ => return Err(format_err!("wrong answer"));
        }
    }
}
@r3v2d0g r3v2d0g self-assigned this Dec 2, 2019
@r3v2d0g r3v2d0g added the bug Something isn't working label Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants