Struct lunatic::protocol::Protocol

source ·
pub struct Protocol<P: 'static, S = Bincode, Z: 'static = ()> { /* private fields */ }
Expand description

A Protocol is a specific type of Process.

It uses session types to check during compile time that all messages exchanged between two processes are in the correct order and of the correct type.

Only Protocol<End> or Protocol<TaskEnd> can be dropped. All other protocols will panic if dropped without reaching Protocol<End> or `Protocol.

Implementations§

source§

impl<P, S, Z> Protocol<P, S, Z>

source

pub fn id(&self) -> u64

Returns the process ID for the local node.

source

pub fn node_id(&self) -> u64

Returns the node ID.

source

pub fn tag(&self) -> Tag

Returns the protocol tag.

source

pub fn from_process<M, S2>(process: Process<M, S2>) -> Self

Turn a process into a protocol.

This implicityly creates a new tag.

source

pub fn from_process_with_tag<M, S2>(process: Process<M, S2>, tag: Tag) -> Self

Turn a process into a protocol using a given Tag.

source§

impl<P, A, S, Z> Protocol<Send<A, P>, S, Z>where S: CanSerialize<A>,

source

pub fn send(self, message: A) -> Protocol<P, S, Z>

Send a value of type A over the session. Returns a session with protocol P.

source§

impl<P, A, S, Z> Protocol<Recv<A, P>, S, Z>where S: CanSerialize<A>,

source

pub fn receive(self) -> (Protocol<P, S, Z>, A)

Receives a value of type A from the session. Returns a tuple containing the resulting session and the received value.

source§

impl<A, S, Z> Protocol<Recv<A, TaskEnd>, S, Z>where S: CanSerialize<A>,

source

pub fn result(self) -> A

A task is a special case of a protocol spawned with the spawn!(@task ...) macro. It only returns one value.

source

pub fn result_timeout(self, duration: Duration) -> Result<A, MailboxError>

A task is a special case of a protocol spawned with the spawn!(@task ...) macro. It only returns one value.

source§

impl<P, Q, S, Z> Protocol<Choose<P, Q>, S, Z>where S: CanSerialize<bool>,

source

pub fn select_left(self) -> Protocol<P, S, Z>

Perform an active choice, selecting protocol P.

source

pub fn select_right(self) -> Protocol<Q, S, Z>

Perform an active choice, selecting protocol Q.

source§

impl<P, Q, S, Z> Protocol<Offer<P, Q>, S, Z>where S: CanSerialize<bool>,

source

pub fn offer(self) -> Branch<Protocol<P, S, Z>, Protocol<Q, S, Z>>

Passive choice. This allows the other end of the session to select one of two options for continuing the protocol: either P or Q.

source§

impl<P, S, Z> Protocol<Rec<P>, S, Z>

source

pub fn repeat(self) -> Protocol<P, S, Protocol<Rec<P>, S, Z>>

Repeat Protocol

source§

impl<P2, S, Z> Protocol<Pop, S, Protocol<P2, S, Z>>

source

pub fn pop(self) -> Protocol<P2, S, Z>

Pop

Trait Implementations§

source§

impl<P, S, Z> Debug for Protocol<P, S, Z>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<P: 'static, S, Z: 'static> Drop for Protocol<P, S, Z>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<P, M, S, S2> From<Process<M, S>> for Protocol<P, S2>

source§

fn from(process: Process<M, S>) -> Self

Converts to this type from the input type.
source§

impl<P, S, Z> From<Protocol<Rec<P>, S, Z>> for Protocol<P, S, Z>

source§

fn from(p: Protocol<Rec<P>, S, Z>) -> Self

Converts to this type from the input type.
source§

impl<P: Hash + 'static, S: Hash, Z: Hash + 'static> Hash for Protocol<P, S, Z>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more

Auto Trait Implementations§

§

impl<P, S, Z> RefUnwindSafe for Protocol<P, S, Z>where P: RefUnwindSafe, S: RefUnwindSafe, Z: RefUnwindSafe,

§

impl<P, S, Z> Send for Protocol<P, S, Z>where P: Send, S: Send, Z: Send,

§

impl<P, S, Z> Sync for Protocol<P, S, Z>where P: Sync, S: Sync, Z: Sync,

§

impl<P, S, Z> Unpin for Protocol<P, S, Z>where P: Unpin, S: Unpin, Z: Unpin,

§

impl<P, S, Z> UnwindSafe for Protocol<P, S, Z>where P: UnwindSafe, S: UnwindSafe, Z: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.