RequestGuard

Struct RequestGuard 

Source
pub struct RequestGuard<Req, Resp>
where Req: Send, Resp: Send,
{ /* private fields */ }
Expand description

Request guard that enforces B must reply

This guard ensures that B must call reply() before dropping the guard. If the guard is dropped without replying, it will panic to prevent A from deadlocking.

强制 B 必须回复的 Guard

这个 guard 确保 B 必须在丢弃 guard 之前调用 reply()。 如果 guard 在没有回复的情况下被丢弃,会 panic 以防止 A 死锁。

Implementations§

Source§

impl<Req, Resp> RequestGuard<Req, Resp>
where Req: Send, Resp: Send,

Source

pub fn request(&self) -> &Req

Get a reference to the request

获取请求内容的引用

Source

pub fn reply(self, resp: Resp)

Consume the guard and send reply

This method will send the response back to the requester.

消耗 Guard 并发送回复

这个方法会将响应发送回请求方。

Trait Implementations§

Source§

impl<Req, Resp> Debug for RequestGuard<Req, Resp>
where Req: Send + Debug, Resp: Send,

Source§

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

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

impl<Req, Resp> Drop for RequestGuard<Req, Resp>
where Req: Send, Resp: Send,

Drop guard: If B drops the guard without calling reply, we panic. This enforces the “must reply” protocol.

Drop 守卫:如果 B 不调用 reply 就丢弃了 Guard,我们会 panic。 这强制执行了 “必须回复” 的协议。

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<Req, Resp> PartialEq for RequestGuard<Req, Resp>
where Req: Send + PartialEq, Resp: Send,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<Req, Resp> Freeze for RequestGuard<Req, Resp>
where Req: Freeze,

§

impl<Req, Resp> !RefUnwindSafe for RequestGuard<Req, Resp>

§

impl<Req, Resp> Send for RequestGuard<Req, Resp>

§

impl<Req, Resp> Sync for RequestGuard<Req, Resp>
where Req: Sync,

§

impl<Req, Resp> Unpin for RequestGuard<Req, Resp>
where Req: Unpin,

§

impl<Req, Resp> !UnwindSafe for RequestGuard<Req, Resp>

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.