1mod stream;
2
3use tokio::io::{AsyncRead, AsyncWrite};
4
5pub use lace_sans_io::core::CarrierRole;
6pub(crate) use stream::{ByteStreamCarrier, TransportIoActivity};
7
8impl crate::ConnectedPeer {
9 pub fn from_duplex<IO>(
15 role: CarrierRole,
16 io: IO,
17 options: crate::ConnectedPeerOptions,
18 ) -> crate::Result<Self>
19 where
20 IO: AsyncRead + AsyncWrite + Unpin + Send + 'static,
21 {
22 let inputs = crate::runtime::connected_inputs(options)?;
23 Ok(Self {
24 lease: crate::runtime::ConnectedTransportLease {
25 transport: Box::new(ByteStreamCarrier::from_duplex(io)),
26 role,
27 },
28 inputs,
29 })
30 }
31
32 pub fn from_split<R, W>(
38 role: CarrierRole,
39 reader: R,
40 writer: W,
41 options: crate::ConnectedPeerOptions,
42 ) -> crate::Result<Self>
43 where
44 R: AsyncRead + Unpin + Send + 'static,
45 W: AsyncWrite + Unpin + Send + 'static,
46 {
47 let inputs = crate::runtime::connected_inputs(options)?;
48 Ok(Self {
49 lease: crate::runtime::ConnectedTransportLease {
50 transport: Box::new(ByteStreamCarrier::from_split(reader, writer)),
51 role,
52 },
53 inputs,
54 })
55 }
56}