-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Add MessageHandler #309
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Closed
I have force-pushed changes. It changes the doc links for MessageHandler so that they use the new intra-doc-feature. |
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.
…he MessageHandler
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
4 tasks
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 themsg!
macro.Some public but hidden API is modified, so it should not break code.
Fix #214 .
Checklist
cargo test
.