Skip to main content

Envelope

Struct Envelope 

Source
pub struct Envelope {
    pub payload: Arc<dyn Any + Send + Sync>,
    pub reply: OneshotSender<Box<dyn Any + Send + Sync>>,
}
Expand description

寻址信封(非泛型,payload 抹平)。

Fields§

§payload: Arc<dyn Any + Send + Sync>

请求载荷(由发起方 Box 于 Arc 中;接收方 downcast 到自身契约类型)。

§reply: OneshotSender<Box<dyn Any + Send + Sync>>

义务回包:成功 Box::new(Ok(Res)),契约错 Box::new(Err(ReplyErr::InvalidPayload))。 handler panic 时 reply 随信封 drop → 信道关闭 → 发起方立即 TargetGone。

Implementations§

Source§

impl Envelope

Source

pub fn new( payload: Arc<dyn Any + Send + Sync>, ) -> (Envelope, OneshotReceiver<Box<dyn Any + Send + Sync>>)

发起方构造helper:由 ctx.ask 使用。

Source

pub fn handle<Req, Res>(event: &Event, handler: impl FnOnce(&Req) -> Res)
where Req: Any + Send + Sync, Res: Any + Send + Sync,

接收方标准处理(B 侧唯一入口helper):

  • payload downcast 成功 → handler(&req),回 Ok(Res);
  • payload downcast 失败 → 回 Err(ReplyErr::InvalidPayload);
  • event 载荷不是 Envelope → 静默忽略(错入 type 的兜底);
  • handler panic → 本函数帧先 unwind,reply 未 send → drop 断连(天然错误信令)。

Auto Trait Implementations§

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.