Struct mini_io_queue::nonblocking::Writer
source · [−]pub struct Writer<S> { /* private fields */ }nonblocking 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
sourceimpl<S> Writer<S>
impl<S> Writer<S>
sourcepub fn is_reader_open(&self) -> bool
pub fn is_reader_open(&self) -> bool
Returns if the corresponding reader is still open.
If this is false, any attempt to write or flush the object will fail.
sourcepub fn has_space(&self) -> bool
pub fn has_space(&self) -> bool
Returns if space is available in the writer’s buffer.
If this is true it is guaranteed that the next call to 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.
sourcepub fn is_flushed(&self) -> bool
pub fn is_flushed(&self) -> bool
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.
sourcepub fn buf<T>(&mut self) -> RegionMut<'_, T> where
S: Storage<T>,
pub fn buf<T>(&mut self) -> RegionMut<'_, T> where
S: Storage<T>,
Gets the writable buffer.
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 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 no space is currently available, or the reader has closed.
Panics
This function may panic if the underlying storage panics when trying to get a slice to the data. This may happen if queue was created with a ring that has a larger capacity than the storage.
sourcepub fn write<T>(&mut self, buf: &[T]) -> usize where
S: Storage<T>,
T: Clone,
pub fn write<T>(&mut self, buf: &[T]) -> usize where
S: Storage<T>,
T: Clone,
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 three scenarios:
- No space is available to write.
- The reader has closed.
- The buffer specified had a length of 0.
Trait Implementations
sourceimpl<S> Write for Writer<S> where
S: Storage<u8>,
Available on crate feature std-io only.
impl<S> Write for Writer<S> where
S: Storage<u8>,
std-io only.sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written. Read more
sourcefn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)Determines if this Writer has an efficient write_vectored
implementation. Read more
1.0.0 · sourcefn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this writer. Read more
sourcefn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Attempts to write multiple buffers into this writer. Read more
Auto Trait Implementations
impl<S> RefUnwindSafe for Writer<S> where
S: RefUnwindSafe,
impl<S> Send for Writer<S> where
S: Send + Sync,
impl<S> Sync for Writer<S> where
S: Send + Sync,
impl<S> Unpin for Writer<S>
impl<S> UnwindSafe for Writer<S> where
S: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more