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

Adds items to 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 reader is still open.

If this is false, any attempt to write or flush the object will fail.

Returns if space is available in the writer’s buffer.

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

Keep in mind that when using a reader and writer on separate threads, a writer that has no space can have more made available at any time - even between calls to has_space and other functions.

Returns if the buffer is flushed, i.e there are no items to read and any read operations will stall.

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

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

Attempt to get the writable buffer, blocking to wait for more space if it is empty.

This functions is a lower-level call. It needs to be paired with the feed method to function properly. When calling this method, none of the contents will be “written” in the sense that later calling empty_buf may return the same contents. As such, feed must be called with the number of items that have been written to the buffer to ensure that the items are never returned twice.

An empty buffer returned indicates that the queue cannot be written to as the reader has closed.

Marks items at the start of the writer buffer as ready to be read, removing them from the slice returned by empty_buf and making them available in the reader’s buffer.

Panics

This function will panic if amt is larger than the writer’s available space buffer.

Writes some items from a buffer into this queue, returning how many items were written.

This function will attempt to write the entire contents of buf, but the entire write may not succeed if not enough space is 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 reader has closed.
  2. The buffer specified had a length of 0.

Attempts to write all items in a buffer into this queue.

If the reader closes before all items are written, an error of the kind WriteError::ReaderClosed will be returned.

Return

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

Flush the buffer, ensuring that any items waiting to be read are consumed by the reader.

If the reader is closed, returns FlushError::ReaderClosed. If blocking cannot be completed immediately, this method blocks until the reader closed or the buffer is flushed.

Close the writer, flushing any remaining data and indicating to the reader that no more data will be written.

Any future read operations will fail. Closing the writer multiple times has no effect.

Trait Implementations

Executes the destructor for this type. Read more

Write a buffer into this writer, returning how many bytes were written. Read more

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

Like write, except that it writes from a slice of buffers. Read more

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

Determines if this Writer has an efficient write_vectored implementation. Read more

Attempts to write an entire buffer into this writer. Read more

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

Attempts to write multiple buffers into this writer. Read more

Writes a formatted string into this writer, returning any error encountered. Read more

Creates a “by reference” adapter for this instance of Write. 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.