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

Add MessageHandler #309

Merged
merged 10 commits into from
Mar 2, 2021
Merged

Add MessageHandler #309

merged 10 commits into from
Mar 2, 2021

Conversation

scrabsha
Copy link
Contributor

@scrabsha scrabsha commented Feb 22, 2021

This PR adds the MessageHandler type and its API.

MsgHandler allows to match over messages, depending on the message type and on the type of the data they store. It aims to replace the msg! macro.

Some public but hidden API is modified, so it should not break code.

Fix #214 .

Checklist
  • tests are passing with cargo test.
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message is clear

@scrabsha
Copy link
Contributor Author

scrabsha commented Mar 2, 2021

I have force-pushed changes. It changes the doc links for MessageHandler so that they use the new intra-doc-feature.

scrabsha added 9 commits March 2, 2021 15:58
This commit adds very basic implementation of MessageHandler. This structure
stores a SignedMessage, and calls, depending on which kind of message it is, and
on its underlying type, either a specified closure, or a fallback one.

The goal is to provide an API that would be nicer to work with than the msg!
macro.

Current implementation features a state-machine like algorithm and currently
only handles messages that can responded to (aka "questions").
This allows us not to trust caller of AnswerSender::reply to provide a
correct signature. As such, the corresponding method can be documented.

This is necessary because such method may be called in the closure that
are passed to MessageHandler::with_question.

Note: this commit renames AnswerSender::send to AnswerSender::respond, and
removes the signature part. This method is public but not documented. As
such, this theorically breaking change should not break any code.
This allows us to match on both regular messages (the ones we can't
respond to) as well as the broadcasts. It follows the same model
established previously.
Previous implementation of MessageHandler always returned nothing, as it
was not considered important. However, returning something is important
at least in the fibonacci example.

This commit allows the MessageHandler to return some data. It requires
every matcher to return the same data type. This data is stored in the
MessageHandler and returned by the on_fallback function.
This allows us to remove additional code.
@o0Ignition0o o0Ignition0o merged commit 835be05 into bastion-rs:master Mar 2, 2021
@scrabsha scrabsha deleted the fix-214-2 branch March 25, 2021 12:42
scrabsha added a commit to scrabsha/bastion that referenced this pull request Mar 25, 2021
[Previous pull request](1) introduced the MessageHandler datatype, but did
not export it in the prelude.

[1]: bastion-rs#309
scrabsha added a commit to scrabsha/bastion that referenced this pull request Mar 25, 2021
Previous pull request[1] introduced the MessageHandler datatype, but did
not export it in the prelude.

[1]: bastion-rs#309
scrabsha added a commit to scrabsha/bastion that referenced this pull request Mar 25, 2021
Previous pull request[1] introduced the MessageHandler datatype, but did
not export it in the prelude.

Examples have been updated so that they don't import MessageHandler manually.

[1]: bastion-rs#309
vertexclique pushed a commit that referenced this pull request Mar 26, 2021
Previous pull request[1] introduced the MessageHandler datatype, but did
not export it in the prelude.

Examples have been updated so that they don't import MessageHandler manually.

[1]: #309
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

the msg! macro
2 participants