Expand description
This crate provides a set of procedural macros for deriving traits for
multi-sender types, which are structs that contain multiple Sender
and
AsyncSender
fields. The structs can either have named fields or be a
tuple struct.
The derive macros provided by this crate allows multi-senders to be created from anything that behaves like all of the individual senders, and allows the multi-sender to be used like any of the individual senders. This can be very useful when one component needs to send multiple kinds of messages to another component; for example the networking layer needs to send multiple types of messages to the ClientActor, each expecting a different response; it would be very cumbersome to have to construct the PeerManagerActor by passing in 10 different sender objects, so instead we create a multi-sender interface of all the senders and pass that in instead.
To better understand these macros,
- Look at the tests in this crate for examples of what the macros generate.
- Search for usages of the derive macros in the codebase.
Derive Macrosยง
- Multi
Send - Derives the ability to use this struct of
Sender
s andAsyncSender
s to call.send
or.send_async
directly as if using one of the includedSender
s orAsyncSender
s. - Multi
Send Message - Derives two enums, whose names are based on this struct by appending
Message
andInput
. Each enum has a case for eachSender
orAsyncSender
in this struct. TheMessage
enum contains the raw message being sent, which isX
forSender<X>
andMessageWithCallback<X, Y>
forAsyncSender<X, Y>
. TheInput
enum contains the same forSender
but only the input,X
forAsyncSender<X, Y>
. - Multi
Sender From - Derives the ability to convert an object into this struct of Sender and
AsyncSenders, as long as the object can be converted into each individual
Sender or AsyncSender.
The conversion is done by calling
.as_multi_sender()
or.into_multi_sender()
.