Splittable

Trait Splittable 

Source
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 in compio::net implement this trait without any lock thanks to the underlying sockets’ duplex nature.
  • File and named pipes in compio::fs implement this trait with ReadHalf and WriteHalf 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 or Split, which wrap the type in a unsynced or synced lock respectively.

Required Associated Types§

Source

type ReadHalf

The type of the read half, which normally implements AsyncRead or AsyncReadAt.

Source

type WriteHalf

The type of the write half, which normally implements AsyncWrite or AsyncWriteAt.

Required Methods§

Source

fn split(self) -> (Self::ReadHalf, Self::WriteHalf)

Consumes self and returns a tuple containing separate read and write halves.

The returned halves can be used independently to perform read and write operations respectively, potentially from different tasks concurrently.

Implementations on Foreign Types§

Source§

impl<R, W> Splittable for (R, W)

Source§

type ReadHalf = R

Source§

type WriteHalf = W

Source§

fn split(self) -> (Self::ReadHalf, Self::WriteHalf)

Implementors§