Macro tarpc::service[][src]

macro_rules! service {
    (
        $(
            $(#[$attr:meta])*
            rpc $fn_name:ident( $( $arg:ident : $in_:ty ),* ) $(-> $out:ty)* $(| $error:ty)*;
        )*
    ) => { ... };
    (
        {
            $(#[$attr:meta])*
            rpc $fn_name:ident( $( $arg:ident : $in_:ty ),* );

            $( $unexpanded:tt )*
        }
        $( $expanded:tt )*
    ) => { ... };
    (
        {
            $(#[$attr:meta])*
            rpc $fn_name:ident( $( $arg:ident : $in_:ty ),* ) -> $out:ty;

            $( $unexpanded:tt )*
        }
        $( $expanded:tt )*
    ) => { ... };
    (
        {
            $(#[$attr:meta])*
            rpc $fn_name:ident( $( $arg:ident : $in_:ty ),* ) | $error:ty;

            $( $unexpanded:tt )*
        }
        $( $expanded:tt )*
    ) => { ... };
    (
        {
            $(#[$attr:meta])*
            rpc $fn_name:ident( $( $arg:ident : $in_:ty ),* ) -> $out:ty | $error:ty;

            $( $unexpanded:tt )*
        }
        $( $expanded:tt )*
    ) => { ... };
    (
        { } // none left to expand
        $(
            $(#[$attr:meta])*
            rpc $fn_name:ident ( $( $arg:ident : $in_:ty ),* ) -> $out:ty | $error:ty;
        )*
    ) => { ... };
}

The main macro that creates RPC services.

Rpc methods are specified, mirroring trait syntax:

/// Say hello
rpc hello(name: String) -> String;

Attributes can be attached to each rpc. These attributes will then be attached to the generated service traits' corresponding fns, as well as to the client stubs' RPCs.

The following items are expanded in the enclosing module:

  • FutureService -- the trait defining the RPC service via a Future API.
  • SyncService -- a service trait that provides a synchronous API for when spawning a thread per request is acceptable.
  • FutureServiceExt -- provides the methods for starting a service. There is an umbrella impl for all implers of FutureService. It's a separate trait to prevent name collisions with RPCs.
  • SyncServiceExt -- same as FutureServiceExt but for SyncService.
  • FutureClient -- a client whose RPCs return Futures.
  • SyncClient -- a client whose RPCs block until the reply is available. Easiest interface to use, as it looks the same as a regular function call.