pub struct RpcChannel<S: Service, C: ServiceEndpoint<SC> = BoxedServiceEndpoint<S>, SC: Service = S> {
pub send: C::SendSink,
pub recv: C::RecvStream,
pub map: Arc<dyn MapService<SC, S>>,
}
Expand description
A channel for requests and responses for a specific service.
This just groups the sink and stream into a single type, and attaches the information about the service type.
Sink and stream are independent, so you can take the channel apart and use them independently.
Type parameters:
S
is the service type.
SC
is the service type that is compatible with the connection.
C
is the service endpoint from which the channel was created.
Fields§
§send: C::SendSink
Sink to send responses to the client.
recv: C::RecvStream
Stream to receive requests from the client.
map: Arc<dyn MapService<SC, S>>
Mapper to map between S and S2
Implementations§
Source§impl<S, C> RpcChannel<S, C, S>where
S: Service,
C: ServiceEndpoint<S>,
impl<S, C> RpcChannel<S, C, S>where
S: Service,
C: ServiceEndpoint<S>,
Sourcepub fn new(send: C::SendSink, recv: C::RecvStream) -> Self
pub fn new(send: C::SendSink, recv: C::RecvStream) -> Self
Create a new RPC channel.
Source§impl<SC, S, C> RpcChannel<S, C, SC>
impl<SC, S, C> RpcChannel<S, C, SC>
Sourcepub fn map<SNext>(self) -> RpcChannel<SNext, C, SC>
pub fn map<SNext>(self) -> RpcChannel<SNext, C, SC>
Map this channel’s service into an inner service.
This method is available if the required bounds are upheld: SNext::Req: Into<S::Req> + TryFrom<S::Req>, SNext::Res: Into<S::Res> + TryFrom<S::Res>,
Where SNext is the new service to map to and S is the current inner service.
This method can be chained infintely.
Source§impl<SC, C, S> RpcChannel<S, C, SC>
impl<SC, C, S> RpcChannel<S, C, SC>
Sourcepub async fn bidi_streaming<M, F, Str, T>(
self,
req: M,
target: T,
f: F,
) -> Result<(), RpcServerError<C>>where
M: BidiStreamingMsg<S>,
F: FnOnce(T, M, UpdateStream<SC, C, M::Update, S>) -> 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,
target: T,
f: F,
) -> Result<(), RpcServerError<C>>where
M: BidiStreamingMsg<S>,
F: FnOnce(T, M, UpdateStream<SC, C, M::Update, S>) -> 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.
Source§impl<S, C, SC> RpcChannel<S, C, SC>
impl<S, C, SC> RpcChannel<S, C, SC>
Sourcepub async fn client_streaming<M, F, Fut, T>(
self,
req: M,
target: T,
f: F,
) -> Result<(), RpcServerError<C>>where
M: ClientStreamingMsg<S>,
F: FnOnce(T, M, UpdateStream<SC, C, M::Update, S>) -> 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,
target: T,
f: F,
) -> Result<(), RpcServerError<C>>where
M: ClientStreamingMsg<S>,
F: FnOnce(T, M, UpdateStream<SC, C, M::Update, S>) -> 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.
Source§impl<S, C, SC> RpcChannel<S, C, SC>
impl<S, C, SC> RpcChannel<S, C, SC>
Sourcepub async fn rpc<M, F, Fut, T>(
self,
req: M,
target: T,
f: F,
) -> Result<(), RpcServerError<C>>
pub async fn rpc<M, F, Fut, T>( self, req: M, target: T, f: F, ) -> Result<(), RpcServerError<C>>
handle the message of type 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 rpc_map_err<M, F, Fut, T, R, E1, E2>(
self,
req: M,
target: T,
f: F,
) -> Result<(), RpcServerError<C>>
pub async fn rpc_map_err<M, F, Fut, T, R, E1, E2>( self, req: M, target: T, f: F, ) -> Result<(), RpcServerError<C>>
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.
Source§impl<S, C, SC> RpcChannel<S, C, SC>
impl<S, C, SC> RpcChannel<S, C, SC>
Sourcepub async fn server_streaming<M, F, Str, T>(
self,
req: M,
target: T,
f: F,
) -> Result<(), RpcServerError<C>>
pub async fn server_streaming<M, F, Str, T>( self, req: M, target: T, f: F, ) -> Result<(), RpcServerError<C>>
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.
Source§impl<SC, C, S> RpcChannel<S, C, SC>
impl<SC, C, S> RpcChannel<S, C, SC>
Sourcepub async fn try_server_streaming<M, F, Fut, Str, T>(
self,
req: M,
target: T,
f: F,
) -> Result<(), RpcServerError<C>>where
M: TryServerStreamingMsg<S>,
Result<M::Item, M::ItemError>: Into<S::Res> + TryFrom<S::Res>,
Result<StreamCreated, M::CreateError>: Into<S::Res> + TryFrom<S::Res>,
F: FnOnce(T, M) -> Fut + Send + 'static,
Fut: Future<Output = Result<Str, M::CreateError>> + Send + 'static,
Str: Stream<Item = Result<M::Item, M::ItemError>> + Send + 'static,
T: Send + 'static,
pub async fn try_server_streaming<M, F, Fut, Str, T>(
self,
req: M,
target: T,
f: F,
) -> Result<(), RpcServerError<C>>where
M: TryServerStreamingMsg<S>,
Result<M::Item, M::ItemError>: Into<S::Res> + TryFrom<S::Res>,
Result<StreamCreated, M::CreateError>: Into<S::Res> + TryFrom<S::Res>,
F: FnOnce(T, M) -> Fut + Send + 'static,
Fut: Future<Output = Result<Str, M::CreateError>> + Send + 'static,
Str: Stream<Item = Result<M::Item, M::ItemError>> + 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.
Compared to RpcChannel::server_streaming, with this method the stream creation is via a function that returns a future that resolves to a stream.