Request

Struct Request 

Source
pub struct Request<Send, Recv> { /* private fields */ }
Expand description

If you need synchronous RPC, you can use this utility

use lifeline::request::Request;

struct Send(usize);
#[derive(Debug, Eq, PartialEq)]
struct Recv(usize);

lifeline::test::block_on(async {
  let (request, mut recv) = Request::send(Send(42));

  // send the request along a channel, and in a service:
  request.reply(|send| async move { Recv(send.0) }).await;

  let resp = recv.await;
  assert_eq!(Ok(Recv(42)), resp);
})

Implementations§

Source§

impl<Send, Recv> Request<Send, Recv>

Source

pub fn send(send: Send) -> (Self, Receiver<Recv>)

Constructs a pair of Request, and Receiver for the response

Source

pub async fn reply<Fn, Fut>(self, respond: Fn) -> Result<(), Recv>
where Fn: FnOnce(Send) -> Fut, Fut: Future<Output = Recv>,

Asynchronously replies to the given request, using the provided closure

Auto Trait Implementations§

§

impl<Send, Recv> Freeze for Request<Send, Recv>
where Send: Freeze,

§

impl<Send, Recv> !RefUnwindSafe for Request<Send, Recv>

§

impl<Send, Recv> Send for Request<Send, Recv>
where Send: Send, Recv: Send,

§

impl<Send, Recv> Sync for Request<Send, Recv>
where Send: Sync, Recv: Send,

§

impl<Send, Recv> Unpin for Request<Send, Recv>
where Send: Unpin,

§

impl<Send, Recv> !UnwindSafe for Request<Send, Recv>

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> Task for T

Source§

fn task<Out>( name: &str, fut: impl Future<Output = Out> + Send + 'static, ) -> Lifeline
where Out: Debug + Send + 'static, Self: Sized,

Spawns an infallible task using the provided executor, wrapping it in a Lifeline handle. The task will run until it finishes, or until the Lifeline is droped.
Source§

fn try_task<Out>( name: &str, fut: impl Future<Output = Result<Out>> + Send + 'static, ) -> Lifeline
where Out: Debug + 'static, Self: Sized,

Spawns an fallible task using the provided executor, wrapping it in a Lifeline handle. The task will run until it finishes, or until the Lifeline is droped. Read more
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.