pub struct RpcServer<S: Service, C: ChannelTypes> { /* private fields */ }
Expand description
A server channel for a specific service.
This is a wrapper around a crate::ServerChannel that serves as the entry point for the server DSL.
S
is the service type, C
is the channel type.
Implementations§
source§impl<S: Service, C: ChannelTypes> RpcServer<S, C>
impl<S: Service, C: ChannelTypes> RpcServer<S, C>
sourcepub fn new(channel: C::ServerChannel<S::Req, S::Res>) -> Self
pub fn new(channel: C::ServerChannel<S::Req, S::Res>) -> Self
Create a new server channel from a channel and a service type.
sourcepub fn local_addr(&self) -> &[LocalAddr]
pub fn local_addr(&self) -> &[LocalAddr]
The local addresses this server is bound to.
This is useful for publicly facing addresses when you start the server with a random
port, :0
and let the kernel choose the real bind address. This will return the
address with the actual port used.
source§impl<S: Service, C: ChannelTypes> RpcServer<S, C>
impl<S: Service, C: ChannelTypes> RpcServer<S, C>
sourcepub async fn accept_one(
&self
) -> Result<(S::Req, (C::SendSink<S::Res>, C::RecvStream<S::Req>)), RpcServerError<C>>where
C::RecvStream<S::Req>: Unpin,
pub async fn accept_one(
&self
) -> Result<(S::Req, (C::SendSink<S::Res>, C::RecvStream<S::Req>)), RpcServerError<C>>where
C::RecvStream<S::Req>: Unpin,
Accepts a connection, handling the first request.
This accepts a new client connection, which is represented as a tuple of a sender and receiver channel.
The return value is a tuple of (request, (channel_sender, channel_receiver))
.
Here request
is the first request which is already read from the channel. The
channels are used to send responses and/or receive more requests.
sourcepub async fn rpc_map_err<M, F, Fut, T, R, E1, E2>(
&self,
req: M,
chan: (C::SendSink<S::Res>, C::RecvStream<S::Req>),
target: T,
f: F
) -> Result<(), RpcServerError<C>>where
M: Msg<S, Pattern = Rpc, Response = Result<R, E2>>,
F: FnOnce(T, M) -> Fut,
Fut: Future<Output = Result<R, E1>>,
E2: From<E1>,
T: Send + 'static,
pub async fn rpc_map_err<M, F, Fut, T, R, E1, E2>(
&self,
req: M,
chan: (C::SendSink<S::Res>, C::RecvStream<S::Req>),
target: T,
f: F
) -> Result<(), RpcServerError<C>>where
M: Msg<S, Pattern = Rpc, Response = Result<R, E2>>,
F: FnOnce(T, M) -> Fut,
Fut: Future<Output = Result<R, E1>>,
E2: From<E1>,
T: Send + 'static,
A rpc call that also maps the error from the user type to the wire type
This is useful if you want to write your function with a convenient error type like anyhow::Error, yet still use a serializable error type on the wire.
sourcepub async fn rpc<M, F, Fut, T>(
&self,
req: M,
chan: (C::SendSink<S::Res>, C::RecvStream<S::Req>),
target: T,
f: F
) -> Result<(), RpcServerError<C>>where
M: Msg<S, Pattern = Rpc>,
F: FnOnce(T, M) -> Fut,
Fut: Future<Output = M::Response>,
T: Send + 'static,
pub async fn rpc<M, F, Fut, T>(
&self,
req: M,
chan: (C::SendSink<S::Res>, C::RecvStream<S::Req>),
target: T,
f: F
) -> Result<(), RpcServerError<C>>where
M: Msg<S, Pattern = Rpc>,
F: FnOnce(T, M) -> Fut,
Fut: Future<Output = M::Response>,
T: Send + 'static,
handle the message M using the given function on the target object
If you want to support concurrent requests, you need to spawn this on a tokio task yourself.
sourcepub async fn client_streaming<M, F, Fut, T>(
&self,
req: M,
c: (C::SendSink<S::Res>, C::RecvStream<S::Req>),
target: T,
f: F
) -> Result<(), RpcServerError<C>>where
M: Msg<S, Pattern = ClientStreaming>,
F: FnOnce(T, M, UpdateStream<S, C, M>) -> Fut + Send + 'static,
Fut: Future<Output = M::Response> + Send + 'static,
T: Send + 'static,
pub async fn client_streaming<M, F, Fut, T>(
&self,
req: M,
c: (C::SendSink<S::Res>, C::RecvStream<S::Req>),
target: T,
f: F
) -> Result<(), RpcServerError<C>>where
M: Msg<S, Pattern = ClientStreaming>,
F: FnOnce(T, M, UpdateStream<S, C, M>) -> Fut + Send + 'static,
Fut: Future<Output = M::Response> + Send + 'static,
T: Send + 'static,
handle the message M using the given function on the target object
If you want to support concurrent requests, you need to spawn this on a tokio task yourself.
sourcepub async fn bidi_streaming<M, F, Str, T>(
&self,
req: M,
c: (C::SendSink<S::Res>, C::RecvStream<S::Req>),
target: T,
f: F
) -> Result<(), RpcServerError<C>>where
M: Msg<S, Pattern = BidiStreaming>,
F: FnOnce(T, M, UpdateStream<S, C, M>) -> Str + Send + 'static,
Str: Stream<Item = M::Response> + Send + 'static,
T: Send + 'static,
pub async fn bidi_streaming<M, F, Str, T>(
&self,
req: M,
c: (C::SendSink<S::Res>, C::RecvStream<S::Req>),
target: T,
f: F
) -> Result<(), RpcServerError<C>>where
M: Msg<S, Pattern = BidiStreaming>,
F: FnOnce(T, M, UpdateStream<S, C, M>) -> Str + Send + 'static,
Str: Stream<Item = M::Response> + Send + 'static,
T: Send + 'static,
handle the message M using the given function on the target object
If you want to support concurrent requests, you need to spawn this on a tokio task yourself.
sourcepub async fn server_streaming<M, F, Str, T>(
&self,
req: M,
c: (C::SendSink<S::Res>, C::RecvStream<S::Req>),
target: T,
f: F
) -> Result<(), RpcServerError<C>>where
M: Msg<S, Pattern = ServerStreaming>,
F: FnOnce(T, M) -> Str + Send + 'static,
Str: Stream<Item = M::Response> + Send + 'static,
T: Send + 'static,
pub async fn server_streaming<M, F, Str, T>(
&self,
req: M,
c: (C::SendSink<S::Res>, C::RecvStream<S::Req>),
target: T,
f: F
) -> Result<(), RpcServerError<C>>where
M: Msg<S, Pattern = ServerStreaming>,
F: FnOnce(T, M) -> Str + Send + 'static,
Str: Stream<Item = M::Response> + Send + 'static,
T: Send + 'static,
handle the message M using the given function on the target object
If you want to support concurrent requests, you need to spawn this on a tokio task yourself.