Struct ReplyContext

Source
pub struct ReplyContext<T, E>(/* private fields */);
Expand description

Object used to respond to requests that have been received by a Server.

Implementations§

Source§

impl<T, E> ReplyContext<T, E>

Source

pub fn reply(self, data: T) -> Result<(), Error<E>>

Send a reply back to originating client.

§Example
use std::thread;
use ump::channel;

let (server, client) = channel::<String, String, ()>();
let server_thread = thread::spawn(move || {
  let (data, rctx) = server.wait().unwrap();
  let reply = format!("Hello, {}!", data);
  rctx.reply(reply).unwrap();
});
let msg = String::from("Client");
let reply = client.req(msg).unwrap();
assert_eq!(reply, "Hello, Client!");
server_thread.join().unwrap();
§Errors

If the originating caller is no longer waiting for a reply (i.e. was dropped) Error::OriginDisappeared is returned.

§Semantics

This call is safe to make after the server context has been released.

Source

pub fn fail(self, err: E) -> Result<(), Error<E>>

Return an error to originating client. This will cause the calling client to return an error. The error passed in the err parameter will be wrapped in a Error::App(err).

§Example
use std::thread;
use ump::{channel, Error};

#[derive(Debug, PartialEq)]
enum MyError {
  SomeError(String)
}

let (server, client) = channel::<String, String, MyError>();
let server_thread = thread::spawn(move || {
  let (_, rctx) = server.wait().unwrap();
  rctx.fail(MyError::SomeError("failed".to_string())).unwrap();
});
let msg = String::from("Client");
let reply = client.req(msg);
match reply {
  Err(Error::App(MyError::SomeError(s))) => {
    assert_eq!(s, "failed");
  }
  _ => {
    panic!("Unexpected return value");
  }
}
server_thread.join().unwrap();
§Errors

If the originating caller is no longer waiting for a reply (i.e. was dropped) Error::OriginDisappeared is returned.

§Semantics

This call is safe to make after the server context has been released.

Trait Implementations§

Source§

impl<T, E> TryFrom<SetCtx<T, RCtxState, E>> for ReplyContext<T, E>

Source§

fn try_from( sctx: SetCtx<T, RCtxState, E>, ) -> Result<ReplyContext<T, E>, <ReplyContext<T, E> as TryFrom<SetCtx<T, RCtxState, E>>>::Error>

Convert a SetCtx into a ReplyContext.

Sets the SetCtx’s stat to Active.

Source§

type Error = Error<E>

The type returned in the event of a conversion error.

Auto Trait Implementations§

§

impl<T, E> Freeze for ReplyContext<T, E>

§

impl<T, E> !RefUnwindSafe for ReplyContext<T, E>

§

impl<T, E> Send for ReplyContext<T, E>
where T: Send, E: Send,

§

impl<T, E> Sync for ReplyContext<T, E>
where T: Send, E: Send,

§

impl<T, E> Unpin for ReplyContext<T, E>

§

impl<T, E> !UnwindSafe for ReplyContext<T, E>

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