mpstthree/binary/struct_trait/
send.rs

1//! This module contains the definition and associated functions and traits
2//! for the Send structure.
3
4use crate::binary::struct_trait::recv::Recv;
5use crate::binary::struct_trait::session::Session;
6
7use crossbeam_channel::{bounded, Sender};
8
9use std::marker;
10
11/// Send `T`, then continue as `S`.
12#[must_use]
13#[derive(Debug)]
14pub struct Send<T, S>
15where
16    T: marker::Send,
17    S: Session,
18    S::Dual: Session,
19{
20    #[doc(hidden)]
21    pub channel: Sender<(T, S::Dual)>,
22}
23
24impl<T: marker::Send, S: Session> Session for Send<T, S> {
25    type Dual = Recv<T, S::Dual>;
26
27    fn new() -> (Self, Self::Dual) {
28        let (sender, receiver) = bounded::<(T, S::Dual)>(1);
29        (Send { channel: sender }, Recv { channel: receiver })
30    }
31
32    fn head_str() -> String {
33        "Send".to_string()
34    }
35
36    fn tail_str() -> String {
37        format!("{}<{}>", S::head_str(), S::tail_str())
38    }
39
40    fn self_head_str(&self) -> String {
41        "Send".to_string()
42    }
43
44    fn self_tail_str(&self) -> String {
45        format!("{}<{}>", S::head_str(), S::tail_str())
46    }
47}