#[repr(C)]
pub struct BytesWriter { /* private fields */ }
Expand description

A BytesWriter enables a writer to directly access mutable bytes within a reserved section with explicit size at the current end of a Queue. In some cases this can result in reduced write latency by eliminating a copy. It also enables Queue to be directly integrated with components which write directly to memory.

A BytesWriter internally wraps a write DocumentContext, and so holds the Queue write lock for the duration of its scope. As with DocumentContext it is recommended to use the scoped form of BytesWriter which automatically handles closure when dropped.

The size of the section of queue reserved by a BytesWriter can be adjusted using resize, and similarly to DocumentContext write attempts can be abandoned using rollback_on_close without changing the state of the Queue.

Data written using a BytesWriter is normally read using a complementary BytesReader.

Example

let mut appender = queue.acquire_appender().unwrap();
{
    let mut writer = appender.scoped_bytes_writer(MSGSIZE);
    let slice = writer.as_mut().as_slice();
    ...
    // directly write to the slice (which writes directly to the Queue)
    ...
    // write lock released and write atomically committed as the writer goes out of scope
}

Implementations§

Get a mutable slice to the reserved section of the Queue as a &mut [u8]

Resize the reserved section of the Queue wrapped by this BytesWriter

The reserved size can be extended as well as shrunk. The actual size of data written to the Queue will be the original size requested when creating the BytesWriter, or whichever size was passed to the most recent resize call.

Abandon a write. Any changes will be discarded when this BytesWriter goes out of scope, and the state of the Queue will be as it was before the BytesWriter was created.

Trait Implementations§

§

type Id

A type-level representation of the type’s C++ namespace and type name. 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.