mesh::rpc

Struct Rpc

Source
pub struct Rpc<I, R>(/* private fields */);
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>.

Implementations§

Source§

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

Source

pub fn detached(input: I) -> Rpc<I, R>

Returns a new RPC message with input and no one listening for the result.

Source

pub fn input(&self) -> &I

Returns the input to the RPC.

Source

pub fn split(self) -> (I, Rpc<(), R>)

Splits the RPC into its input and an input-less RPC. This is useful when the input is needed in one place but the RPC will be completed in another.

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> Rpc<I, Result<R, RemoteError>>
where R: 'static + Send,

Source

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

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 + Sync + Send>>,

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, R> Debug for Rpc<I, R>
where I: Debug, R: Debug,

Source§

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

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

impl<I, R> DefaultEncoding for Rpc<I, R>
where I: 'static + MeshField + Send, R: 'static + MeshField + Send,

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: 'static + MeshField + Send, R: 'static + MeshField + Send,

Source§

const DECODERS: &'static [ErasedDecoderEntry] = _

The list of decoder vtables.
Source§

impl<I, R> StructEncodeMetadata<Resource> for Rpc<I, R>
where I: 'static + MeshField + Send, R: 'static + MeshField + Send,

Source§

const ENCODERS: &'static [ErasedEncoderEntry] = _

The list of encoder vtables.
Source§

impl<I, R> StructMetadata for Rpc<I, R>
where I: 'static + MeshField + Send, R: 'static + MeshField + Send,

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.

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, R: Send,

§

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

§

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: 'static + MeshPayload + Send,

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