Struct RpcChannel

Source
pub struct RpcChannel<S, C = BoxedStreamTypes<<S as Service>::Req, <S as Service>::Res>>
where S: Service, C: ChannelTypes<S>,
{ pub send: <C as StreamTypes>::SendSink, pub recv: <C as StreamTypes>::RecvStream, /* private fields */ }
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. C is the service endpoint from which the channel was created.

Fields§

§send: <C as StreamTypes>::SendSink

Sink to send responses to the client.

§recv: <C as StreamTypes>::RecvStream

Stream to receive requests from the client.

Implementations§

Source§

impl<S, C> RpcChannel<S, C>
where S: Service, C: StreamTypes<In = <S as Service>::Req, Out = <S as Service>::Res>,

Source

pub fn new( send: <C as StreamTypes>::SendSink, recv: <C as StreamTypes>::RecvStream, ) -> RpcChannel<S, C>

Create a new RPC channel.

Source

pub fn boxed(self) -> RpcChannel<S>
where <C as ConnectionErrors>::SendError: Into<Error> + Send + Sync + 'static, <C as ConnectionErrors>::RecvError: Into<Error> + Send + Sync + 'static,

Convert this channel into a boxed channel.

Source

pub fn map<SNext>( self, ) -> RpcChannel<SNext, MappedStreamTypes<<SNext as Service>::Req, <SNext as Service>::Res, C>>
where SNext: Service, <SNext as Service>::Req: TryFrom<<S as Service>::Req>, <S as Service>::Res: From<<SNext as Service>::Res>,

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<C, S> RpcChannel<S, C>
where C: StreamTypes<In = <S as Service>::Req, Out = <S as Service>::Res>, S: Service,

Source

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<C, <M as BidiStreamingMsg<S>>::Update>) -> Str + Send + 'static, Str: Stream<Item = <M as BidiStreamingMsg<S>>::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> RpcChannel<S, C>
where S: Service, C: StreamTypes<In = <S as Service>::Req, Out = <S as Service>::Res>,

Source

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<C, <M as ClientStreamingMsg<S>>::Update>) -> Fut + Send + 'static, Fut: Future<Output = <M as ClientStreamingMsg<S>>::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> RpcChannel<S, C>
where S: Service, C: StreamTypes<In = <S as Service>::Req, Out = <S as Service>::Res>,

Source

pub async fn rpc<M, F, Fut, T>( self, req: M, target: T, f: F, ) -> Result<(), RpcServerError<C>>
where M: RpcMsg<S>, F: FnOnce(T, M) -> Fut, Fut: Future<Output = <M as RpcMsg<S>>::Response>, T: Send + 'static,

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.

Source

pub async fn rpc_map_err<M, F, Fut, T, R, E1, E2>( self, req: M, target: T, f: F, ) -> Result<(), RpcServerError<C>>
where M: RpcMsg<S, 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.

Source§

impl<S, C> RpcChannel<S, C>
where S: Service, C: StreamTypes<In = <S as Service>::Req, Out = <S as Service>::Res>,

Source

pub async fn server_streaming<M, F, Str, T>( self, req: M, target: T, f: F, ) -> Result<(), RpcServerError<C>>
where M: ServerStreamingMsg<S>, F: FnOnce(T, M) -> Str + Send + 'static, Str: Stream<Item = <M as ServerStreamingMsg<S>>::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> RpcChannel<S, C>
where C: StreamTypes<In = <S as Service>::Req, Out = <S as Service>::Res>, S: Service,

Source

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 as TryServerStreamingMsg<S>>::Item, <M as TryServerStreamingMsg<S>>::ItemError>: Into<<S as Service>::Res> + TryFrom<<S as Service>::Res>, Result<StreamCreated, <M as TryServerStreamingMsg<S>>::CreateError>: Into<<S as Service>::Res> + TryFrom<<S as Service>::Res>, F: FnOnce(T, M) -> Fut + Send + 'static, Fut: Future<Output = Result<Str, <M as TryServerStreamingMsg<S>>::CreateError>> + Send + 'static, Str: Stream<Item = Result<<M as TryServerStreamingMsg<S>>::Item, <M as TryServerStreamingMsg<S>>::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.

Trait Implementations§

Source§

impl<S, C> Debug for RpcChannel<S, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S, C> Freeze for RpcChannel<S, C>

§

impl<S, C> RefUnwindSafe for RpcChannel<S, C>

§

impl<S, C> Send for RpcChannel<S, C>

§

impl<S, C> Sync for RpcChannel<S, C>

§

impl<S, C> Unpin for RpcChannel<S, C>
where S: Unpin,

§

impl<S, C> UnwindSafe for RpcChannel<S, C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more