pub struct Reader<S> { /* private fields */ }
Available on crate feature blocking only.
Expand description

Receives items from the queue.

Values sent by the writer will be added to the end of the reader’s buffer, and capacity can be sent back to the writer from the start of the reader’s buffer to allow it to write more data.

Implementations

Returns if the corresponding writer is still open.

If this is false, unread data will still be available to read but a well-behaved writer will not provide any new data.

Returns if data is available in the reader’s buffer.

If this is true it is guaranteed that the next call to fill_buf will return a non-empty slice, unless consume is called first.

Keep in mind that when using a reader and writer on separate threads, a reader that has no data can receive data at any time - even between calls to has_data and other functions.

Returns if the buffer is full, i.e all space is allocated to the reader and any write operations will block.

If this is true a reader can only resume the writer by calling consume to pass capacity to the writer.

Keep in mind that when using a reader and writer on separate threads, a reader that is not full can become full at any time - even between calls to is_full and other functions.

Attempt to read from the reader’s buffer, blocking to wait for more data if it is empty.

This function is a lower-level call. It needs to be paired with the consume method to function properly. When calling this method, none of the contents will be “read” in the sense that later calling fill_buf may return the same contents. As such, consume must be called with the number of bytes that are consumed from this buffer to ensure that the items are never returned twice.

An empty buffer returned indicates that all data has been read and the writer has closed.

Marks items at the start of the reader buffer as consumed, removing them from the slice returned by fill_buf and adding their capacity to the end of the writer’s buffer. Since queues have a fixed underlying length, calling this is required to allow the transfer of more data.

Panics

This function will panic if amt is larger than the reader’s available data buffer.

Pulls some items from this queue into the specified buffer, returning how many items were read.

This method will complete immediately if at least one item is available to read, otherwise it will block until some are available.

Return

It is guaranteed that the return value is <= buf.len().

A return value of 0 indicates one of these two scenarios:

  1. The writer has closed and all items have been read.
  2. The buffer specified had a length of 0.

Reads the exact number of items required to fill buf.

If the writer closes before the buffer is completely filled, an error of the kind ReadExactError::WriterClosed will be returned.

Return

If the return value is Ok(n), it is guaranteed that n == buf.len().

Close the reader, indicating to the writer that no more data will be read.

Any in-progress writes or flushes on the writer will be interrupted, and any future operations will fail. Closing the reader multiple times has no effect.

Dropping the reader object will also close it.

Trait Implementations

Returns the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more

Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to read. Read more

🔬This is a nightly-only experimental API. (buf_read_has_data_left)

Check if the underlying Read has any data left to be read. Read more

Read all bytes into buf until the delimiter byte or EOF is reached. Read more

Read all bytes until a newline (the 0xA byte) is reached, and append them to the provided buffer. You do not need to clear the buffer before appending. Read more

Returns an iterator over the contents of this reader split on the byte byte. Read more

Returns an iterator over the lines of this reader. Read more

Executes the destructor for this type. Read more

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

Like read, except that it reads into a slice of buffers. Read more

🔬This is a nightly-only experimental API. (can_vector)

Determines if this Reader has an efficient read_vectored implementation. Read more

Read all bytes until EOF in this source, placing them into buf. Read more

Read all bytes until EOF in this source, appending them to buf. Read more

Read the exact number of bytes required to fill buf. Read more

🔬This is a nightly-only experimental API. (read_buf)

Pull some bytes from this source into the specified buffer. Read more

🔬This is a nightly-only experimental API. (read_buf)

Read the exact number of bytes required to fill buf. Read more

Creates a “by reference” adaptor for this instance of Read. Read more

Transforms this Read instance to an Iterator over its bytes. Read more

Creates an adapter which will chain this stream with another. Read more

Creates an adapter which will read at most limit bytes from it. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.