Macro distant_net::router
source · [−]macro_rules! router {
(
$(#[router($($mname:ident = $mvalue:literal),*)])?
$vis:vis $name:ident {
$($transport:ident : $res_ty:ty => $req_ty:ty),+ $(,)?
}
) => { ... };
}
Expand description
Creates a new struct around a UntypedTransport
that routes incoming
and outgoing messages to different transports, enabling the ability to transform a singular
transport into multiple typed transports that can be combined with Client
and Server
to mix having a variety of clients and servers available on the
same underlying UntypedTransport
.
use distant_net::router;
// Create a router that produces three transports from one:
// 1. `Transport<u8, String>` - receives `String` and sends `u8`
// 2. `Transport<bool, CustomData>` - receives `CustomData` and sends `bool`
// 3. `Transport<Option<String>, u8>` - receives `u8` and sends `Option<String>`
router!(TestRouter {
one: String => u8,
two: CustomData => bool,
three: u8 => Option<String>,
});
router!(
#[router(inbound = 10, outbound = 20)]
TestRouterWithCustomBounds {
one: String => u8,
two: CustomData => bool,
three: u8 => Option<String>,
}
);
let router = TestRouter::new(transport);
let one = router.one; // MpscTransport<u8, String>
let two = router.two; // MpscTransport<bool, CustomData>
let three = router.three; // MpscTransport<Option<String>, u8>