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

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

Receive a value of type T on B from A. 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_b_from_a;
use mpstthree::functionmpst::send::send_mpst_a_to_b;

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

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

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

// From this point...

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

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

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

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

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

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

let _ = send_mpst_a_to_b((), sess_a);
let _ = recv_mpst_b_from_a(sess_b).unwrap();