Trait Splittable
pub trait Splittable {
type ReadHalf;
type WriteHalf;
// Required method
fn split(self) -> (Self::ReadHalf, Self::WriteHalf);
}Available on crate feature
io only.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,UnixStreamand references to them incompio::netimplement this trait without any lock thanks to the underlying sockets’ duplex nature.Fileand named pipes incompio::fsimplement this trait withReadHalfandWriteHalfbeing 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
Split, which wrap the type in a unsynced or synced lock depends on whethersyncfeature is turned on.
Required Associated Types§
type ReadHalf
type ReadHalf
The type of the read half, which normally implements AsyncRead or
AsyncReadAt.
type WriteHalf
type WriteHalf
The type of the write half, which normally implements AsyncWrite or
AsyncWriteAt.