Struct mesh_channel::rpc::Rpc

source ·
pub struct Rpc<I, R>(pub I, pub OneshotSender<R>);
Expand description

An RPC message for a request with input of type I and output of type R. The receiver of the message should process the request and return results via the Sender<R>.

Tuple Fields§

§0: I§1: OneshotSender<R>

Implementations§

source§

impl<I, R: 'static + Send> Rpc<I, R>

source

pub fn handle_sync<F>(self, f: F)
where F: FnOnce(I) -> R,

Handles an RPC request by calling f and sending the result to the initiator.

source

pub async fn handle<F, Fut>(self, f: F)
where F: FnOnce(I) -> Fut, Fut: Future<Output = R>,

Handles an RPC request by calling f, awaiting its result, and sending the result to the initiator.

source

pub async fn handle_must_succeed<F, Fut, E>(self, f: F) -> Result<(), E>
where F: FnOnce(I) -> Fut, Fut: Future<Output = Result<R, E>>,

Handles an RPC request by calling f, awaiting its result, and sending Ok results back to the initiator.

If f fails, the error is propagated back to the caller, and the RPC channel is dropped (resulting in a RecvError::Closed on the initiator).

source

pub fn complete(self, result: R)

Completes the RPC with the specified result value.

source§

impl<I, R: 'static + Send> Rpc<I, Result<R, RemoteError>>

source

pub fn handle_failable_sync<F, E>(self, f: F)
where F: FnOnce(I) -> Result<R, E>, E: Into<Box<dyn Error + Send + Sync>>,

Handles an RPC request by calling f and sending the result to the initiator, after converting any error to a RemoteError.

source

pub async fn handle_failable<F, Fut, E>(self, f: F)
where F: FnOnce(I) -> Fut, Fut: Future<Output = Result<R, E>>, E: Into<Box<dyn Error + Send + Sync>>,

Handles an RPC request by calling f, awaiting its result, and sending the result to the initiator, after converting any error to a RemoteError.

Trait Implementations§

source§

impl<I: Debug, R: Debug> Debug for Rpc<I, R>

source§

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

Formats the value using the given formatter. Read more
source§

impl<I, R> DefaultEncoding for Rpc<I, R>
where I: MeshField, R: MeshField,

source§

type Encoding = TableEncoder

The encoding to use for the serialization. Read more
source§

impl<'encoding, I, R> StructDecodeMetadata<'encoding, Resource> for Rpc<I, R>
where I: MeshField, R: MeshField,

source§

const DECODERS: &'static [ErasedDecoderEntry] = _

The list of decoder vtables.
source§

impl<I, R> StructEncodeMetadata<Resource> for Rpc<I, R>
where I: MeshField, R: MeshField,

source§

const ENCODERS: &'static [ErasedEncoderEntry] = _

The list of encoder vtables.
source§

impl<I, R> StructMetadata for Rpc<I, R>
where I: MeshField, R: MeshField,

source§

const NUMBERS: &'static [u32] = _

The field numbers for each field.
source§

const OFFSETS: &'static [usize] = _

The byte offset to each field within the struct.
source§

impl<I, R, I_mapped, R_mapped> Downcast<Rpc<I_mapped, R_mapped>> for Rpc<I, R>
where I: MeshField + Downcast<I_mapped>, R: MeshField, OneshotSender<R>: Downcast<OneshotSender<R_mapped>>,

Auto Trait Implementations§

§

impl<I, R> Freeze for Rpc<I, R>
where I: Freeze,

§

impl<I, R> !RefUnwindSafe for Rpc<I, R>

§

impl<I, R> Send for Rpc<I, R>
where I: Send,

§

impl<I, R> Sync for Rpc<I, R>
where I: Sync,

§

impl<I, R> Unpin for Rpc<I, R>
where I: Unpin,

§

impl<I, R> !UnwindSafe for Rpc<I, R>

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> SerializeMessage for T
where T: MeshPayload,

source§

type Concrete = T

The underlying concrete message type.
source§

fn compute_message_size(&mut self, sizer: MessageSizer<'_>)

Computes the message size, as in MessageEncode::compute_message_size.
source§

fn write_message(self, writer: MessageWriter<'_, '_, Resource>)

Writes the message, as in MessageEncode::write_message.
source§

fn extract(self) -> <T as SerializeMessage>::Concrete

Extract the concrete message.
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
source§

impl<T, U> Upcast<U> for T
where U: Downcast<T>,