Struct Chan

Source
pub struct Chan<P, E, R> { /* private fields */ }
Expand description

A session typed channel. P is the protocol and E is the environment, containing potential recursion targets. R is the representation of messages, which could be DynMessage, or perhaps something we know statically how to turn into JSON or bytes.

Implementations§

Source§

impl<E, R> Chan<Eps, E, R>

Source

pub fn close(self) -> SessionResult<()>

Close a channel. Should always be used at the end of your program.

Source§

impl<P, E, R> Chan<P, E, R>

Source

pub fn abort<T, F: Error + Send + 'static>(self, e: F) -> SessionResult<T>

Close the channel and return an error due to some business logic violation.

Source

pub fn abort_dyn<T>(self, e: Box<dyn Error + Send>) -> SessionResult<T>

Source§

impl<P, E, T, R: Repr<T>> Chan<Send<T, P>, E, R>

Source

pub fn send(self, v: T) -> SessionResult<Chan<P, E, R>>

Send a value of type T over the channel. Returns a channel with protocol P.

Source§

impl<P, E, T, R: Repr<T>> Chan<Recv<T, P>, E, R>

Source

pub async fn recv(self, timeout: Duration) -> SessionResult<(Chan<P, E, R>, T)>

Receives a value of type T from the channel. Returns a tuple containing the resulting channel and the received value.

Source§

impl<P: Outgoing, Q: Outgoing, E, R> Chan<Choose<P, Q>, E, R>

Source

pub fn sel1(self) -> Chan<P, E, R>

Perform an active choice, selecting protocol P. We haven’t sent any value yet, so the agency stays on our side.

Source

pub fn sel2(self) -> Chan<Q, E, R>

Perform an active choice, selecting protocol Q. We haven’t sent any value yet, so the agency stays on our side.

Source§

impl<P: Incoming, Q: Incoming, E, R> Chan<Offer<P, Q>, E, R>
where P::Expected: 'static, R: Repr<P::Expected>,

Source

pub async fn offer( self, t: Duration, ) -> SessionResult<Branch<Chan<P, E, R>, Chan<Q, E, R>>>

Passive choice. This allows the other end of the channel to select one of two options for continuing the protocol: either P or Q. Both options mean they will have to send a message to us, the agency is on their side.

Source§

impl<P, E, R> Chan<Rec<P>, E, R>

Source

pub fn enter(self) -> Chan<P, (P, E), R>

Enter a recursive environment, putting the current environment on the top of the environment stack.

Source§

impl<P, E, R> Chan<Var<Z>, (P, E), R>

Source

pub fn zero(self) -> SessionResult<Chan<P, (P, E), R>>

Recurse to the environment on the top of the environment stack. The agency must be kept, since there’s no message exchange here, we just start from the top as a continuation of where we are.

Source§

impl<P, E, N, R> Chan<Var<S<N>>, (P, E), R>

Source

pub fn succ(self) -> Chan<Var<N>, E, R>

Pop the top environment from the environment stack.

Trait Implementations§

Source§

impl<P, E, R> Drop for Chan<P, E, R>

A sanity check destructor that kicks in if we abandon the channel by returning Ok(_) without closing it first.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<P, E, R> Freeze for Chan<P, E, R>
where R: Freeze,

§

impl<P, E, R> RefUnwindSafe for Chan<P, E, R>

§

impl<P, E, R> Send for Chan<P, E, R>
where R: Send, P: Send, E: Send,

§

impl<P, E, R> Sync for Chan<P, E, R>
where R: Sync + Send, P: Sync, E: Sync,

§

impl<P, E, R> Unpin for Chan<P, E, R>
where R: Unpin, P: Unpin, E: Unpin,

§

impl<P, E, R> UnwindSafe for Chan<P, E, R>
where R: UnwindSafe, P: UnwindSafe, E: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.