Macro define_dispatch

Source
macro_rules! define_dispatch {
    (@ep_arm blocking ($endpoint:ty) $handler:ident $context:ident $header:ident $req:ident $outputter:ident ($spawn_fn:path) $spawner:ident) => { ... };
    (@ep_arm async ($endpoint:ty) $handler:ident $context:ident $header:ident $req:ident $outputter:ident ($spawn_fn:path) $spawner:ident) => { ... };
    (@ep_arm spawn ($endpoint:ty) $handler:ident $context:ident $header:ident $req:ident $outputter:ident ($spawn_fn:path) $spawner:ident) => { ... };
    (@tp_arm blocking $handler:ident $context:ident $header:ident $msg:ident $outputter:ident ($spawn_fn:path) $spawner:ident) => { ... };
    (@tp_arm async $handler:ident $context:ident $header:ident $msg:ident $outputter:ident ($spawn_fn:path) $spawner:ident) => { ... };
    (@tp_arm spawn $handler:ident $context:ident $header:ident $msg:ident $outputter:ident ($spawn_fn:path) $spawner:ident) => { ... };
    (@matcher
        $n:literal $app_name:ident $tx_impl:ty; $spawn_fn:ident $key_ty:ty; $key_kind:expr;
        $req_key_name:ident / $topic_key_name:ident = $bytes_ty:ty;
        ($($endpoint:ty | $ep_flavor:tt | $ep_handler:ident)*)
        ($($topic_in:ty | $tp_flavor:tt | $tp_handler:ident)*)
    ) => { ... };
    (
        app: $app_name:ident;

        spawn_fn: $spawn_fn:ident;
        tx_impl: $tx_impl:ty;
        spawn_impl: $spawn_impl:ty;
        context: $context_ty:ty;

        endpoints: {
            list: $endpoint_list:path;

               | EndpointTy     | kind          | handler           |
               | $(-)*          | $(-)*         | $(-)*             |
            $( | $endpoint:ty   | $ep_flavor:tt | $ep_handler:ident  | )*
        };
        topics_in: {
            list: $topic_in_list:path;

               | TopicTy        | kind          | handler           |
               | $(-)*          | $(-)*         | $(-)*             |
            $( | $topic_in:ty   | $tp_flavor:tt | $tp_handler:ident  | )*
        };
        topics_out: {
            list: $topic_out_list:path;
        };
    ) => { ... };
}
Expand description

Define Dispatch Macro

§Example

use postcard_rpc::define_dispatch;
use postcard_rpc::server::impls::test_channels::dispatch_impl::*;

// This creates a type that implements the `Dispatcher` trait
define_dispatch! {
    // This becomes the name of your dispatcher
    app: SingleDispatcher;
    // This is the spawn function, usually found in the `dispatch_impl` module of your
    // implementation
    spawn_fn: spawn_fn;
    // This is the WireTx impl
    tx_impl: WireTxImpl;
    // This is the WireSpawn impl
    spawn_impl: WireSpawnImpl;
    // This is the TestContext you define to be passed to all handlers
    context: TestContext;

    endpoints: {
        // This is the list you get from the `endpoints()` macro
        list: ENDPOINT_LIST;

        // These are all of your endpoints and the handlers they map to
        | EndpointTy        | kind      | handler               |
        | ----------        | ----      | -------               |
        | AlphaEndpoint     | async     | test_alpha_handler    |
        | BetaEndpoint      | spawn     | test_beta_handler     |
    };
    topics_in: {
        // This is the list you get from the `topics!()` macro
        list: TOPICS_IN_LIST;

        // These are the incoming topics and the handlers they map to
        | TopicTy           | kind      | handler               |
        | ----------        | ----      | -------               |
        | ZetaTopic1        | blocking  | test_zeta_blocking    |
        | ZetaTopic2        | async     | test_zeta_async       |
        | ZetaTopic3        | spawn     | test_zeta_spawn       |
    };
    topics_out: {
        // This is the list you get from the `topics!()` macro
        list: TOPICS_OUT_LIST;

        // NOTE: outgoing topics don't have any handlers!
    };
}