pub struct Delivery<P: Protocol> {
pub to: DeliveryTarget<P>,
pub message: P::Msg,
}Expand description
One pure communication addressed to a concrete protocol signature.
Protocol identity is not inferred from the payload. Consequently, two protocols with the same address and message types still have distinct delivery types.
ⓘ
use behavior::{Actions, Behavior, Delivery, MailAddr, Never, NoBirths, Protocol, Recipient, User};
struct Queue;
struct Worker;
macro_rules! inert {
($actor:ty) => {
impl Protocol for $actor {
type Addr = MailAddr;
type Msg = u8;
}
impl Behavior for $actor {
type Event = User<MailAddr, u8>;
type Sends = Vec<Never>;
type Ph = Never;
type Error = Never;
type Birth = NoBirths;
fn init(&mut self, _: crate::InitializationTurn) -> behavior::BehaviorActed<Self> { Ok(Actions::cont()) }
fn transition(&mut self, _: crate::ActiveTurn, _: 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, Protocol, 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 Protocol for Worker {
type Addr = MailAddr;
type Msg = u8;
}
impl Behavior for Worker {
type Event = User<MailAddr, u8>;
type Sends = Vec<Never>;
type Ph = Never;
type Error = Never;
type Birth = NoBirths;
fn init(&mut self, _: crate::InitializationTurn) -> behavior::BehaviorActed<Self> { Ok(Actions::cont()) }
fn transition(&mut self, _: crate::ActiveTurn, _: 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: DeliveryTarget<P>§message: P::MsgImplementations§
Trait Implementations§
Auto Trait Implementations§
impl<P> Freeze for Delivery<P>
impl<P> RefUnwindSafe for Delivery<P>where
<P as Protocol>::Msg: RefUnwindSafe,
<P as Protocol>::Addr: RefUnwindSafe,
<<P as Protocol>::Addr as Address>::Nonce: RefUnwindSafe,
impl<P> Send for Delivery<P>
impl<P> Sync for Delivery<P>
impl<P> Unpin for Delivery<P>
impl<P> UnsafeUnpin for Delivery<P>where
<P as Protocol>::Msg: UnsafeUnpin,
<P as Protocol>::Addr: UnsafeUnpin,
<<P as Protocol>::Addr as Address>::Nonce: UnsafeUnpin,
impl<P> UnwindSafe for Delivery<P>where
<P as Protocol>::Msg: UnwindSafe,
<P as Protocol>::Addr: UnwindSafe,
<<P as Protocol>::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