Struct quic_rpc::server::RpcChannel

source ·
pub struct RpcChannel<S: Service, C: ServiceEndpoint<S>> {
    pub send: C::SendSink,
    pub recv: C::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.

Fields§

§send: C::SendSink

Sink to send responses to the client.

§recv: C::RecvStream

Stream to receive requests from the client.

Implementations§

source§

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

source

pub fn new(send: C::SendSink, recv: C::RecvStream) -> Self

Create a new channel from a sink and a stream.

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::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 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<S, C, M::Update>) -> 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

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<S, C, M::Update>) -> 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

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

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.

Trait Implementations§

source§

impl<S: Debug + Service, C: Debug + ServiceEndpoint<S>> Debug for RpcChannel<S, C>
where C::SendSink: Debug, C::RecvStream: Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

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