use crate::binary::struct_trait::{send::Send, session::Session};
use std::error::Error;
use std::marker;
use std::net::UdpSocket;
use std::panic;
type UdpData = [u8; 128];
#[cfg_attr(
doc_cfg,
doc(cfg(any(feature = "transport", feature = "transport_udp")))
)]
pub fn send_udp<T, S>(
x: T, data: &UdpData,
s: Send<(T, UdpData), S>,
socket: UdpSocket,
udp: bool,
) -> Result<(S, usize, UdpSocket), Box<dyn Error>>
where
T: marker::Send,
S: Session,
{
let (here, there) = S::new();
match s.channel.send(((x, *data), there)) {
Ok(()) => match udp {
true => {
let result = socket.send(data)?;
Ok((here, result, socket))
}
false => Ok((here, 0, socket)),
},
Err(e) => panic!("{}", e.to_string()),
}
}