Skip to main content

Stream

Trait Stream 

Source
pub trait Stream:
    Read
    + RefRead
    + Write
    + RefWrite
    + StreamCommon {
    type RecvHalf: RecvHalf<Stream = Self>;
    type SendHalf: SendHalf<Stream = Self>;

    // Required methods
    fn set_nonblocking(&self, nonblocking: bool) -> Result<()>;
    fn set_recv_timeout(&self, timeout: Option<Duration>) -> Result<()>;
    fn set_send_timeout(&self, timeout: Option<Duration>) -> Result<()>;
    fn split(self) -> (Self::RecvHalf, Self::SendHalf);
    fn reunite(rh: Self::RecvHalf, sh: Self::SendHalf) -> ReuniteResult<Self>;
    fn from_options(options: &ConnectOptions<'_>) -> Result<Self>;

    // Provided method
    fn connect(name: Name<'_>) -> Result<Self> { ... }
}
Expand description

Local socket stream implementations.

Types on which this trait is implemented are variants of the Stream enum. In addition, it is implemented on Stream itself, which makes it a trait object of sorts. See its documentation for more on the semantics of the methods seen here.

Required Associated Types§

Source

type RecvHalf: RecvHalf<Stream = Self>

Receive half type returned by .split().

Source

type SendHalf: SendHalf<Stream = Self>

Send half type returned by .split().

Required Methods§

Source

fn set_nonblocking(&self, nonblocking: bool) -> Result<()>

Enables or disables the nonblocking mode for the stream. By default, it is disabled.

In nonblocking mode, receiving and sending immediately returns with the WouldBlock error in situations when they would normally block for an uncontrolled amount of time. The specific situations are:

  • Receiving is attempted and there is no new data available;
  • Sending is attempted and the buffer is full due to the other side not yet having received previously sent data.
Source

fn set_recv_timeout(&self, timeout: Option<Duration>) -> Result<()>

Sets the receive timeout to the specified value. If set to None (the default), reads will block indefinitely if there is no data.

Source

fn set_send_timeout(&self, timeout: Option<Duration>) -> Result<()>

Sets the send timeout to the specified value. If set to None (the default), writes will block indefinitely if there is no space in the send buffer.

Source

fn split(self) -> (Self::RecvHalf, Self::SendHalf)

Splits a stream into a receive half and a send half.

You probably want to avoid this mechanism for the following reasons:

  • Placing a stream in an Rc or Arc produces identical behavior, since &Stream implements Read and Write
  • Dropping a half does not shut it down like it does with sockets, which may be counterintuitive
Source

fn reunite(rh: Self::RecvHalf, sh: Self::SendHalf) -> ReuniteResult<Self>

Attempts to reunite a receive half with a send half to yield the original stream back, returning both halves as an error if they belong to different streams (or when using this method on streams that haven’t been split to begin with).

Source

fn from_options(options: &ConnectOptions<'_>) -> Result<Self>

Connects to a local socket server using the specified options.

This method typically shouldn’t be called directly – use the creation methods on ConnectOptions (connect_sync, connect_sync_as) instead.

Provided Methods§

Source

fn connect(name: Name<'_>) -> Result<Self>

Connects to a local socket server.

This is equivalent to ConnectOptions::new().name(name).connect_sync_as::<Self>().

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Stream for interprocess::local_socket::Stream

Source§

impl Stream for interprocess::os::unix::uds_local_socket::Stream

Available on Unix only.