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
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,
Accept one channel from the client, pull out the first request, and return both the first message and the channel for further processing.
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.