Module dispatch

Source
Expand description

A multiple-argument dispatch system for our RPC system.

Our RPC functionality is polymorphic in Methods (what we’re told to do) and Objects (the things that we give the methods to); we want to be able to provide different implementations for each method, on each object.

§Writing RPC functions

To participate in this system, an RPC function must have a particular type:

async fn my_rpc_func(
    target: Arc<OBJTYPE>,
    method: Box<METHODTYPE>,
    ctx: Arc<dyn rpc::Context>,
    [ updates: rpc::UpdateSink<METHODTYPE::Update ] // this argument is optional!
) -> Result<METHODTYPE::Output, impl Into<rpc::RpcError>>
{ ... }

If the “updates” argument is present, then you will need to use the [Updates] flag when registering this function.

§Registering RPC functions statically

After writing a function in the form above, you need to register it with the RPC system so that it can be invoked on objects of the right type. The easiest way to do so is by registering it, using static_rpc_invoke_fn!:

static_rpc_invoke_fn!{ my_rpc_func; my_other_rpc_func; }

You can register particular instantiations of generic types, if they’re known ahead of time:

static_rpc_invoke_fn!{ my_generic_fn::<PreferredRuntime>; }

§Registering RPC functions at runtime.

If you can’t predict all the instantiations of your function in advance, you can insert them into a DispatchTable at run time:

fn install_my_rpc_methods<T>(table: &mut DispatchTable) {
    table.insert(invoker_ent!(my_generic_fn::<T>));
    table.insert(invoker_ent!(my_generic_fn_with_update::<T>));
}

Modules§

description 🔒 describe-methods
Types and code for describing our type-based dispatch system.

Macros§

declare_invocable_impl 🔒
Helper: Declare a blanket implementation for Invocable.

Structs§

DispatchTable
A collection of method implementations for different method and object types.
FuncType 🔒
Actual types to use when looking up a function in our HashMap.
InvokerEnt
An annotated Invocable; used to compile a DispatchTable.

Enums§

InvokeError
An error that occurred while trying to invoke a method on an object.

Traits§

Invocable
An installable handler for running a method on an object type.
RpcInvocable
Subtrait of Invocable that requires its outputs to be serializable as RPC replies.

Type Aliases§

BoxedUpdateSink
A boxed sink on which updates can be sent.
RpcResultFuture
A boxed future holding the result of an RPC method.
SpecialResultFuture 🔒
Type returned by DispatchTable::invoke_special, to represent a future containing a type-erased type.
UpdateSink
A boxed sink on which updates of a particular type can be sent.