pub struct Delivery<B: Behavior> {
pub to: Recipient<B>,
pub message: B::Msg,
}Expand description
One pure communication addressed to a concrete behavior protocol.
Protocol identity is not inferred from the payload. Consequently, two behaviors accepting the same address and message types still have distinct delivery types.
ⓘ
use behavior::{Actions, Behavior, Delivery, MailAddr, Never, NoBirths, Recipient, User};
struct Queue;
struct Worker;
macro_rules! inert {
($actor:ty) => {
impl Behavior for $actor {
type Addr = MailAddr;
type Msg = u8;
type Event = User<MailAddr, u8>;
type Sends = Vec<Never>;
type Ph = Never;
type Error = Never;
type Birth = NoBirths;
fn init(&mut self) -> behavior::BehaviorActed<Self> { Ok(Actions::cont()) }
fn transition(&mut self, _: Self::Event) -> behavior::BehaviorActed<Self> {
Ok(Actions::cont())
}
}
};
}
inert!(Queue);
inert!(Worker);
let worker = Recipient::<Worker>::global(MailAddr(1));
let _: Delivery<Queue> = Delivery::new(worker, 7);A destination also fixes its message and address namespaces:
ⓘ
use behavior::{Actions, Address, Behavior, Delivery, MailAddr, Never, NoBirths, Recipient, User};
#[derive(Clone, Copy, PartialEq, Eq)]
struct OtherAddr(u64);
impl Address for OtherAddr {
type Nonce = u64;
fn birth(self, nonce: u64) -> Self { Self(self.0 ^ nonce) }
}
struct Worker;
impl Behavior for Worker {
type Addr = MailAddr;
type Msg = u8;
type Event = User<MailAddr, u8>;
type Sends = Vec<Never>;
type Ph = Never;
type Error = Never;
type Birth = NoBirths;
fn init(&mut self) -> behavior::BehaviorActed<Self> { Ok(Actions::cont()) }
fn transition(&mut self, _: Self::Event) -> behavior::BehaviorActed<Self> { Ok(Actions::cont()) }
}
let _ = Recipient::<Worker>::global(OtherAddr(1));ⓘ
let worker = Recipient::<Worker>::global(MailAddr(1));
let _ = Delivery::<Worker>::new(worker, "wrong payload");Fields§
§to: Recipient<B>§message: B::MsgImplementations§
Trait Implementations§
impl<B> Eq for Delivery<B>
Auto Trait Implementations§
impl<B> Freeze for Delivery<B>
impl<B> RefUnwindSafe for Delivery<B>where
<B as Behavior>::Msg: RefUnwindSafe,
<B as Behavior>::Addr: RefUnwindSafe,
<<B as Behavior>::Addr as Address>::Nonce: RefUnwindSafe,
impl<B> Send for Delivery<B>
impl<B> Sync for Delivery<B>
impl<B> Unpin for Delivery<B>
impl<B> UnsafeUnpin for Delivery<B>where
<B as Behavior>::Msg: UnsafeUnpin,
<B as Behavior>::Addr: UnsafeUnpin,
<<B as Behavior>::Addr as Address>::Nonce: UnsafeUnpin,
impl<B> UnwindSafe for Delivery<B>where
<B as Behavior>::Msg: UnwindSafe,
<B as Behavior>::Addr: UnwindSafe,
<<B as Behavior>::Addr as Address>::Nonce: UnwindSafe,
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