Struct ReplyContext

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

Object used to reply to requests passed to the 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_ng::{channel, MsgType};

let (server, client) = channel::<(), String, String, ()>();
let server_thread = thread::spawn(move || {
  let MsgType::Request(data, rctx) = server.wait().unwrap() else {
    panic!("Not Request type");
  };
  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_ng::{channel, Error, MsgType};

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

let (server, client) = channel::<String, String, String, MyError>();
let server_thread = thread::spawn(move || {
  let MsgType::Request(_, rctx) = server.wait().unwrap() else {
    panic!("Unexpected message type");
  };
  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

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

§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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V