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
impl Envelope
Sourcepub fn new(
payload: Arc<dyn Any + Send + Sync>,
) -> (Envelope, OneshotReceiver<Box<dyn Any + Send + Sync>>)
pub fn new( payload: Arc<dyn Any + Send + Sync>, ) -> (Envelope, OneshotReceiver<Box<dyn Any + Send + Sync>>)
发起方构造helper:由 ctx.ask 使用。
Sourcepub fn handle<Req, Res>(event: &Event, handler: impl FnOnce(&Req) -> Res)
pub fn handle<Req, Res>(event: &Event, handler: impl FnOnce(&Req) -> Res)
接收方标准处理(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§
impl !Freeze for Envelope
impl !RefUnwindSafe for Envelope
impl !UnwindSafe for Envelope
impl Send for Envelope
impl Sync for Envelope
impl Unpin for Envelope
impl UnsafeUnpin for Envelope
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