use crate::binary::struct_trait::{send::Send, session::Session};
use std::error::Error;
use std::io::Write;
use std::marker;
use std::net::TcpStream;
use std::panic;
type TcpData = [u8; 128];
#[cfg_attr(
doc_cfg,
doc(cfg(any(feature = "transport", feature = "transport_tcp")))
)]
pub fn send_tcp<T, S>(
x: T, data: &TcpData,
s: Send<(T, TcpData), S>,
mut stream: TcpStream,
tcp: bool,
) -> Result<(S, TcpStream), Box<dyn Error>>
where
T: marker::Send,
S: Session,
{
let (here, there) = S::new();
match s.channel.send(((x, *data), there)) {
Ok(()) => {
match tcp {
true => {
stream.write_all(data)?;
Ok((here, stream))
}
false => Ok((here, stream)),
}
}
Err(e) => panic!("{}", e.to_string()),
}
}