Struct ump_server::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>
impl<T, E> ReplyContext<T, E>
sourcepub fn reply(self, data: T) -> Result<(), Error<E>>
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();
Semantics
This call is safe to make after the server context has been released.
sourcepub fn fail(self, err: E) -> Result<(), Error<E>>
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();
Semantics
This call is safe to make after the server context has been released.
Trait Implementations§
source§impl<T, E> From<SetCtx<T, RCtxState, E>> for ReplyContext<T, E>
impl<T, E> From<SetCtx<T, RCtxState, E>> for ReplyContext<T, E>
source§fn from(sctx: SetCtx<T, RCtxState, E>) -> ReplyContext<T, E>
fn from(sctx: SetCtx<T, RCtxState, E>) -> ReplyContext<T, E>
Converts to this type from the input type.
Auto Trait Implementations§
impl<T, E> !RefUnwindSafe for ReplyContext<T, E>
impl<T, E> Send for ReplyContext<T, E>where E: Send, T: Send,
impl<T, E> Sync for ReplyContext<T, E>where E: Send, T: Send,
impl<T, E> Unpin for ReplyContext<T, E>
impl<T, E> !UnwindSafe for ReplyContext<T, E>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more