Struct buf_redux::BufWriter

source ·
pub struct BufWriter<W: Write, P = StdPolicy> { /* private fields */ }
Expand description

A drop-in replacement for std::io::BufWriter with more functionality.

Original method names/signatures and implemented traits are left untouched, making replacement as simple as swapping the import of the type.

By default this type implements the behavior of its std counterpart: it only flushes the buffer if an incoming write is larger than the remaining space.

To change this type’s behavior, change the policy with .set_policy() using a type from the policy module or your own implentation of WriterPolicy.

Policies that perform alternating writes and flushes without completely emptying the buffer may benefit from using a ringbuffer via the new_ringbuf() and with_capacity_ringbuf() constructors. Ringbuffers are only available on supported platforms with the slice-deque feature and have some caveats; see the docs at the crate root for more details.

Implementations

Create a new BufWriter wrapping inner with the default buffer capacity and WriterPolicy.

Create a new BufWriter wrapping inner, utilizing a buffer with a capacity of at least cap bytes and the default WriterPolicy.

The actual capacity of the buffer may vary based on implementation details of the global allocator.

Create a new BufWriter wrapping inner, utilizing a ringbuffer with the default capacity and WriterPolicy.

A ringbuffer never has to move data to make room; consuming bytes from the head simultaneously makes room at the tail. This is useful in conjunction with a policy like FlushExact to ensure there is always room to write more data if necessary, without expensive copying operations.

Only available on platforms with virtual memory support and with the slice-deque feature enabled. The default capacity will differ between Windows and Unix-derivative targets. See Buffer::new_ringbuf() or the crate root docs for more info.

Create a new BufWriter wrapping inner, utilizing a ringbuffer with at least cap capacity and the default WriterPolicy.

A ringbuffer never has to move data to make room; consuming bytes from the head simultaneously makes room at the tail. This is useful in conjunction with a policy like FlushExact to ensure there is always room to write more data if necessary, without expensive copying operations.

Only available on platforms with virtual memory support and with the slice-deque feature enabled. The capacity will be rounded up to the minimum size for the target platform. See Buffer::with_capacity_ringbuf() or the crate root docs for more info.

Create a new BufWriter wrapping inner, utilizing the existing Buffer instance and the default WriterPolicy.

Note

Does not clear the buffer first! If there is data already in the buffer it will be written out on the next flush!

Set a new WriterPolicy, returning the transformed type.

Mutate the current WriterPolicy.

Inspect the current WriterPolicy.

Get a reference to the inner writer.

Get a mutable reference to the inner writer.

Note

If the buffer has not been flushed, writing directly to the inner type will cause data inconsistency.

Get the capacty of the inner buffer.

Get the number of bytes currently in the buffer.

Reserve space in the buffer for at least additional bytes. May not be quite exact due to implementation details of the buffer’s allocator.

Move data to the start of the buffer, making room at the end for more writing.

This is a no-op with the *_ringbuf() constructors (requires slice-deque feature).

Consume self and return both the underlying writer and the buffer

Flush the buffer and unwrap, returning the inner writer on success, or a type wrapping self plus the error otherwise.

Flush the buffer and unwrap, returning the inner writer and any error encountered during flushing.

Trait Implementations

Formats the value using the given formatter. Read more

Attempt to flush the buffer to the underlying writer.

If an error occurs, the thread-local handler is invoked, if one was previously set by set_drop_err_handler for this thread.

Executes the destructor for this type. Read more

Seek to the ofPet, in bytes, in the underlying writer.

Seeking always writes out the internal buffer before seeking.

Rewind to the beginning of a stream. Read more
🔬This is a nightly-only experimental API. (seek_stream_len)
Returns the length of this stream (in bytes). Read more
Returns the current seek position from the start of the stream. 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.