Skip to main content

RecipientAddress

Trait RecipientAddress 

Source
pub trait RecipientAddress: Address + Sized {
    type Established<P>: Clone
       where P: Protocol<Addr = Self>;
}
Expand description

Runtime-owned exact message endpoint family for one logical address namespace.

A runtime implements this trait on its own address newtype, selecting one statically projected endpoint representation for each concrete protocol. The projection may reuse a representation; EstablishedRecipient<P> still preserves P and prevents cross-protocol substitution. Ordinary protocols continue to declare only their canonical Protocol::Addr and Protocol::Msg; they never author endpoint keys or endpoint associated types. An endpoint is cloneable acquaintance evidence, but it is not intrinsically Send: thread transfer is required only by the concrete asynchronous interpretation boundary that performs it.

A local endpoint remains valid, but cannot enter the sendable crate::InterpretSends path:

ⓘ
#[derive(Clone, Copy, PartialEq, Eq)]
struct LocalAddr(u8);
impl behavior::Address for LocalAddr { type Nonce = u8; }
struct LocalEndpoint<P>(std::rc::Rc<()>, core::marker::PhantomData<fn() -> P>);
impl<P> Clone for LocalEndpoint<P> {
    fn clone(&self) -> Self { Self(self.0.clone(), core::marker::PhantomData) }
}
impl behavior::RecipientAddress for LocalAddr {
    type Established<P> = LocalEndpoint<P> where P: behavior::Protocol<Addr = Self>;
}
struct LocalProtocol;
impl behavior::Protocol for LocalProtocol {
    type Addr = LocalAddr;
    type Msg = std::rc::Rc<()>;
}
struct Runtime;
impl<RootEvent, Path> behavior::InterpretItem<behavior::EstablishedDelivery<LocalProtocol>, RootEvent, Path>
    for Runtime
{
    fn interpret_item<'a>(&'a mut self, input: &'a mut Option<behavior::EstablishedDelivery<LocalProtocol>>, received: &'a mut Option<behavior::ItemSettlement<behavior::EstablishedDelivery<LocalProtocol>, (), behavior::ExactDeliveryReason, behavior::Never>>) -> impl core::future::Future<Output = ()> + Send + 'a where behavior::EstablishedDelivery<LocalProtocol>: 'a {
        async move {
            if received.is_some() { return; }
            let Some(delivery) = input.take() else { return; };
            drop(delivery);
            *received = Some(behavior::ItemSettlement::Accepted(()));
        }
    }
}
fn require_async<T>()
where
    T: behavior::InterpretSends<Runtime, behavior::User<LocalAddr, std::rc::Rc<()>>, behavior::Here>,
{}
let endpoint = LocalEndpoint(std::rc::Rc::new(()), core::marker::PhantomData);
let recipient = behavior::EstablishedRecipient::<LocalProtocol>::issued(endpoint);
let _delivery = behavior::EstablishedDelivery::new(recipient, std::rc::Rc::new(()));
require_async::<Vec<behavior::EstablishedDelivery<LocalProtocol>>>();

Required Associated Types§

Source

type Established<P>: Clone where P: Protocol<Addr = Self>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<A: EndpointAddress> RecipientAddress for A

Source§

type Established<P> = <A as EndpointAddress>::Established<P> where P: Protocol<Addr = Self>