pub trait Splittable {
type ReadHalf;
type WriteHalf;
// Required method
fn split(self) -> (Self::ReadHalf, Self::WriteHalf);
}
Expand description
A trait for types that can be split into separate read and write halves.
This trait enables an I/O type to be divided into two separate components: one for reading and one for writing. This is particularly useful in async contexts where you might want to perform concurrent read and write operations from different tasks.
§Implementor
- Any
(R, W)
tuple implements this trait. TcpStream
,UnixStream
and references to them incompio::net
implement this trait without any lock thanks to the underlying sockets’ duplex nature.File
and named pipes incompio::fs
implement this trait withReadHalf
andWriteHalf
being the file itself since it’s reference-counted under the hood.- For other type to be compatible with this trait, it must be wrapped with
UnsyncSplit
orSplit
, which wrap the type in a unsynced or synced lock respectively.
Required Associated Types§
Sourcetype ReadHalf
type ReadHalf
The type of the read half, which normally implements AsyncRead
or
AsyncReadAt
.
Sourcetype WriteHalf
type WriteHalf
The type of the write half, which normally implements AsyncWrite
or
AsyncWriteAt
.