Skip to main content

EndpointAddress

Trait EndpointAddress 

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

Runtime-owned exact 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:

ⓘ
use behavior::{
    Address, EndpointAddress, EstablishedDelivery, EstablishedRecipient,
    Here, InterpretItem, InterpretSends, ItemSettlement, Never, Protocol, User,
};
use core::marker::PhantomData;
use std::rc::Rc;
#[derive(Clone, Copy, PartialEq, Eq)]
struct LocalAddr(u8);
impl Address for LocalAddr { type Nonce = u8; }
struct LocalEndpoint<P>(Rc<()>, PhantomData<fn() -> P>);
impl<P> Clone for LocalEndpoint<P> {
    fn clone(&self) -> Self { Self(self.0.clone(), PhantomData) }
}
impl EndpointAddress for LocalAddr {
    type Established<P> = LocalEndpoint<P> where P: Protocol<Addr = Self>;
}
struct LocalProtocol;
impl Protocol for LocalProtocol {
    type Addr = LocalAddr;
    type Msg = Rc<()>;
}
struct Runtime;
impl<RootEvent, Path> InterpretItem<EstablishedDelivery<LocalProtocol>, RootEvent, Path>
    for Runtime
{
    fn interpret_item(
        &mut self,
        delivery: EstablishedDelivery<LocalProtocol>,
    ) -> impl core::future::Future<Output = ItemSettlement<
        EstablishedDelivery<LocalProtocol>, (), Never, Never,
    >> + Send {
        async move {
            drop(delivery);
            ItemSettlement::Accepted(())
        }
    }
}
fn require_async<T>()
where
    T: InterpretSends<Runtime, User<LocalAddr, Rc<()>>, Here>,
{}
let endpoint = LocalEndpoint(Rc::new(()), PhantomData);
let recipient = EstablishedRecipient::<LocalProtocol>::issued(endpoint);
let _delivery = EstablishedDelivery::new(recipient, Rc::new(()));
require_async::<Vec<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".

Implementors§