Struct quic_rpc_utils::RpcChannel

source ·
pub struct RpcChannel<S, C, SInner = S>
where S: Service, C: ServiceEndpoint<S>, SInner: Service,
{ pub send: <C as ConnectionCommon<<S as Service>::Req, <S as Service>::Res>>::SendSink, pub recv: <C as ConnectionCommon<<S as Service>::Req, <S as Service>::Res>>::RecvStream, pub map: Arc<dyn MapService<S, SInner>>, }
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.

Fields§

§send: <C as ConnectionCommon<<S as Service>::Req, <S as Service>::Res>>::SendSink

Sink to send responses to the client.

§recv: <C as ConnectionCommon<<S as Service>::Req, <S as Service>::Res>>::RecvStream

Stream to receive requests from the client.

§map: Arc<dyn MapService<S, SInner>>

Mapper to map between S and S2

Implementations§

source§

impl<S, C> RpcChannel<S, C>
where S: Service, C: ServiceEndpoint<S>,

source

pub fn new( send: <C as ConnectionCommon<<S as Service>::Req, <S as Service>::Res>>::SendSink, recv: <C as ConnectionCommon<<S as Service>::Req, <S as Service>::Res>>::RecvStream, ) -> RpcChannel<S, C>

Create a new RPC channel.

source§

impl<S, C, SInner> RpcChannel<S, C, SInner>
where S: Service, C: ServiceEndpoint<S>, SInner: Service,

source

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

Map this channel’s service into an inner service.

This method is available if the required bounds are upheld: SNext::Req: IntoSInner::Req + TryFromSInner::Req, SNext::Res: IntoSInner::Res + TryFromSInner::Res,

Where SNext is the new service to map to and SInner is the current inner service.

This method can be chained infintely.

source§

impl<S, C, SInner> RpcChannel<S, C, SInner>
where S: Service, C: ServiceEndpoint<S>, SInner: Service,

source

pub async fn bidi_streaming<M, F, Str, T>( self, req: M, target: T, f: F, ) -> Result<(), RpcServerError<C>>
where M: BidiStreamingMsg<SInner>, F: FnOnce(T, M, UpdateStream<S, C, <M as BidiStreamingMsg<SInner>>::Update, SInner>) -> Str + Send + 'static, Str: Stream<Item = <M as BidiStreamingMsg<SInner>>::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, SInner> RpcChannel<S, C, SInner>
where S: Service, C: ServiceEndpoint<S>, SInner: Service,

source

pub async fn client_streaming<M, F, Fut, T>( self, req: M, target: T, f: F, ) -> Result<(), RpcServerError<C>>
where M: ClientStreamingMsg<SInner>, F: FnOnce(T, M, UpdateStream<S, C, <M as ClientStreamingMsg<SInner>>::Update, SInner>) -> Fut + Send + 'static, Fut: Future<Output = <M as ClientStreamingMsg<SInner>>::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, SInner> RpcChannel<S, C, SInner>
where S: Service, C: ServiceEndpoint<S>, SInner: Service,

source

pub async fn rpc<M, F, Fut, T>( self, req: M, target: T, f: F, ) -> Result<(), RpcServerError<C>>
where M: RpcMsg<SInner>, F: FnOnce(T, M) -> Fut, Fut: Future<Output = <M as RpcMsg<SInner>>::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<SInner, 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, SInner> RpcChannel<S, C, SInner>
where S: Service, C: ServiceEndpoint<S>, SInner: Service,

source

pub async fn server_streaming<M, F, Str, T>( self, req: M, target: T, f: F, ) -> Result<(), RpcServerError<C>>
where M: ServerStreamingMsg<SInner>, F: FnOnce(T, M) -> Str + Send + 'static, Str: Stream<Item = <M as ServerStreamingMsg<SInner>>::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, SInner> RpcChannel<S, C, SInner>
where S: Service, C: ServiceEndpoint<S>, SInner: 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<SInner>, Result<<M as TryServerStreamingMsg<SInner>>::Item, <M as TryServerStreamingMsg<SInner>>::ItemError>: Into<<SInner as Service>::Res> + TryFrom<<SInner as Service>::Res>, Result<StreamCreated, <M as TryServerStreamingMsg<SInner>>::CreateError>: Into<<SInner as Service>::Res> + TryFrom<<SInner as Service>::Res>, F: FnOnce(T, M) -> Fut + Send + 'static, Fut: Future<Output = Result<Str, <M as TryServerStreamingMsg<SInner>>::CreateError>> + Send + 'static, Str: Stream<Item = Result<<M as TryServerStreamingMsg<SInner>>::Item, <M as TryServerStreamingMsg<SInner>>::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, SInner> Debug for RpcChannel<S, C, SInner>
where S: Debug + Service, C: Debug + ServiceEndpoint<S>, SInner: Debug + Service, <C as ConnectionCommon<<S as Service>::Req, <S as Service>::Res>>::SendSink: Debug, <C as ConnectionCommon<<S as Service>::Req, <S as Service>::Res>>::RecvStream: Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S, C, SInner> Freeze for RpcChannel<S, C, SInner>
where <C as ConnectionCommon<<S as Service>::Req, <S as Service>::Res>>::SendSink: Freeze, <C as ConnectionCommon<<S as Service>::Req, <S as Service>::Res>>::RecvStream: Freeze,

§

impl<S, C, SInner = S> !RefUnwindSafe for RpcChannel<S, C, SInner>

§

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

§

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

§

impl<S, C, SInner> Unpin for RpcChannel<S, C, SInner>

§

impl<S, C, SInner = S> !UnwindSafe for RpcChannel<S, C, SInner>

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>,

§

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>,

§

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