-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: create replies directly out of handle_cmd using closure #219
Conversation
|
||
fn make_reply(&self, id: &E::Id, state: &E, evt: E::Evt) -> BoxedAny { | ||
Box::new(self.make_reply(id, state, evt)) | ||
fn handle_cmd(self: Box<Self>, id: &E::Id, state: &E) -> BoxedCmdEffect<E> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL self: Box<Self>
to allow owning Box<dyn ...>
values in trait functions.
Works fine here, too: hseeberger/rusty-accounts#25 |
Looking good! Even though for replies one still might have to match on state (and panic on the wrong variants), there are some significant improvements, e.g. the handlers consuming cmd/evt. |
Ugh, that's still ugly but probably little we can do about that. |
We discussed a similar solution before in #201 (comment)
It now came up again that
make_reply
is hard to use when you need access to the event. In that case the previous solution required manual correlation of the event created inhandle_cmd
with the event passed tomake_reply
. The only way would to unpack the right event type would be to panic on all the other event cases which is inconvenient (in simple cases) and a potential for runtime panics (in more complex cases)./cc @qrilka