Function mpstthree::functionmpst::recv::recv_mpst_a_from_b[][src]

pub fn recv_mpst_a_from_b<T, S1, S2, R>(
    s: MeshedChannels<Recv<T, S1>, S2, RoleB<R>, RoleA<RoleEnd>>
) -> Result<(T, MeshedChannels<S1, S2, R, RoleA<RoleEnd>>), Box<dyn Error>> where
    T: Send,
    S1: Session,
    S2: Session,
    R: Role
Expand description

Receive a value of type T on A from B. Can fail. Returns either a pair of the received value and the continuation of the MeshedChannels<S1, S2, R, N> or an error.

Example

use mpstthree::binary::struct_trait::{end::End, recv::Recv, session::Session};
use mpstthree::meshedchannels::MeshedChannels;
use mpstthree::role::Role;

use mpstthree::role::a::RoleA;
use mpstthree::role::b::RoleB;
use mpstthree::role::end::RoleEnd;

use mpstthree::functionmpst::recv::recv_mpst_a_from_b;
use mpstthree::functionmpst::send::send_mpst_b_to_a;

// Creating the binary sessions
type AtoB = Recv<(), End>;

// Stack
type StackA = RoleB<RoleEnd>;
type StackB = RoleA<RoleEnd>;

// Name
type NameA = RoleA<RoleEnd>;
type NameB = RoleB<RoleEnd>;

// From this point...

let (channel_ab, channel_ba) = AtoB::new();
let (channel_ac, _) = End::new();
let (channel_bc, _) = End::new();

let (role_a, _) = StackA::new();
let (role_b, _) = StackB::new();

let (name_a, _) = NameA::new();
let (name_b, _) = NameB::new();

let sess_a = MeshedChannels {
    session1: channel_ab,
    session2: channel_ac,
    stack: role_a,
    name: name_a,
};

let sess_b = MeshedChannels {
    session1: channel_ba,
    session2: channel_bc,
    stack: role_b,
    name: name_b,
};

// ...to this point, should not be written in general. Please look at the *fork* function.

let _ = send_mpst_b_to_a((), sess_b);
let _ = recv_mpst_a_from_b(sess_a).unwrap();