pub struct Writer<'a, W> { /* private fields */ }Expand description
The Writer is the primary interface for writing values to an avro datafile or a byte container (say a Vec<u8>).
It takes a reference to the schema for validating the values being written
and an output stream W which can be any type
implementing the Write trait.
Implementations§
Source§impl<'a, W: Write> Writer<'a, W>
impl<'a, W: Write> Writer<'a, W>
Sourcepub fn new(schema: &'a Schema, out_stream: W) -> Result<Self, AvrowErr>
pub fn new(schema: &'a Schema, out_stream: W) -> Result<Self, AvrowErr>
Creates a new avro Writer instance taking a reference to a Schema
and a type implementing Write.
Sourcepub fn with_codec(
schema: &'a Schema,
out_stream: W,
codec: Codec,
) -> Result<Self, AvrowErr>
pub fn with_codec( schema: &'a Schema, out_stream: W, codec: Codec, ) -> Result<Self, AvrowErr>
Same as the new method, but additionally takes a Codec as parameter.
Codecs can be used to compress the encoded data being written in an avro datafile.
Supported codecs as per spec are:
Sourcepub fn write<T: Into<Value>>(&mut self, value: T) -> Result<(), AvrowErr>
pub fn write<T: Into<Value>>(&mut self, value: T) -> Result<(), AvrowErr>
Appends a value to the buffer. Before a value gets written, it gets validated with the schema referenced by this writer.
§Note:
writes are buffered internally as per the flush interval (for performance) and the underlying
buffer may not reflect values immediately.
Call flush to explicitly write all buffered data.
Alternatively calling into_inner on the writer
guarantees that flush will happen and will hand over
the underlying buffer with all data written.
Sourcepub fn serialize<T: Serialize>(&mut self, value: T) -> Result<(), AvrowErr>
pub fn serialize<T: Serialize>(&mut self, value: T) -> Result<(), AvrowErr>
Appends a native Rust value to the buffer. The value must implement Serde’s Serialize trait.
Sourcepub fn flush(&mut self) -> Result<(), AvrowErr>
pub fn flush(&mut self) -> Result<(), AvrowErr>
Sync/flush any buffered data to the underlying buffer.
Sourcepub fn into_inner(self) -> Result<W, AvrowErr>
pub fn into_inner(self) -> Result<W, AvrowErr>
Consumes self and yields the inner Write instance.
Additionally calls flush if no flush has happened before this call.