pub struct Writer<'a, W> { /* private fields */ }
Expand description
Main interface for writing Avro formatted values.
Implementations§
Source§impl<'a, W> Writer<'a, W>
impl<'a, W> Writer<'a, W>
Sourcepub fn builder() -> WriterBuilder<'a, ((), (), (), ()), W>
pub fn builder() -> WriterBuilder<'a, ((), (), (), ()), W>
Create a builder for building Writer
.
On the builder, call .schema(...)
, .writer(...)
, .codec(...)
(optional), .block_size(...)
(optional) to set the values of the fields (they accept Into
values).
Finally, call .build()
to create the instance of Writer
.
Source§impl<'a, W: Write> Writer<'a, W>
impl<'a, W: Write> Writer<'a, W>
Sourcepub fn new(schema: &'a Schema, writer: W) -> Self
pub fn new(schema: &'a Schema, writer: W) -> Self
Creates a Writer
given a Schema
and something implementing the io::Write
trait to write
to.
No compression Codec
will be used.
Sourcepub fn with_codec(schema: &'a Schema, writer: W, codec: Codec) -> Self
pub fn with_codec(schema: &'a Schema, writer: W, codec: Codec) -> Self
Creates a Writer
with a specific Codec
given a Schema
and something implementing the
io::Write
trait to write to.
Sourcepub fn append<T: Into<Value>>(&mut self, value: T) -> AvroResult<usize>
pub fn append<T: Into<Value>>(&mut self, value: T) -> AvroResult<usize>
Append a compatible value (implementing the ToAvro
trait) to a Writer
, also performing
schema validation.
Return the number of bytes written (it might be 0, see below).
NOTE This function is not guaranteed to perform any actual write, since it relies on
internal buffering for performance reasons. If you want to be sure the value has been
written, then call flush
.
Sourcepub fn append_value_ref(&mut self, value: &Value) -> AvroResult<usize>
pub fn append_value_ref(&mut self, value: &Value) -> AvroResult<usize>
Append a compatible value to a Writer
, also performing schema validation.
Return the number of bytes written (it might be 0, see below).
NOTE This function is not guaranteed to perform any actual write, since it relies on
internal buffering for performance reasons. If you want to be sure the value has been
written, then call flush
.
Sourcepub fn append_ser<S: Serialize>(&mut self, value: S) -> AvroResult<usize>
pub fn append_ser<S: Serialize>(&mut self, value: S) -> AvroResult<usize>
Append anything implementing the Serialize
trait to a Writer
for
serde
compatibility, also performing schema
validation.
Return the number of bytes written.
NOTE This function is not guaranteed to perform any actual write, since it relies on
internal buffering for performance reasons. If you want to be sure the value has been
written, then call flush
.
Sourcepub fn extend<I, T: Into<Value>>(&mut self, values: I) -> AvroResult<usize>where
I: IntoIterator<Item = T>,
pub fn extend<I, T: Into<Value>>(&mut self, values: I) -> AvroResult<usize>where
I: IntoIterator<Item = T>,
Extend a Writer
with an Iterator
of compatible values (implementing the ToAvro
trait), also performing schema validation.
Return the number of bytes written.
NOTE This function forces the written data to be flushed (an implicit
call to flush
is performed).
Sourcepub fn extend_ser<I, T: Serialize>(&mut self, values: I) -> AvroResult<usize>where
I: IntoIterator<Item = T>,
pub fn extend_ser<I, T: Serialize>(&mut self, values: I) -> AvroResult<usize>where
I: IntoIterator<Item = T>,
Sourcepub fn extend_from_slice(&mut self, values: &[Value]) -> AvroResult<usize>
pub fn extend_from_slice(&mut self, values: &[Value]) -> AvroResult<usize>
Extend a Writer
by appending each Value
from a slice, while also performing schema
validation on each value appended.
Return the number of bytes written.
NOTE This function forces the written data to be flushed (an implicit
call to flush
is performed).
Sourcepub fn flush(&mut self) -> AvroResult<usize>
pub fn flush(&mut self) -> AvroResult<usize>
Flush the content appended to a Writer
. Call this function to make sure all the content
has been written before releasing the Writer
.
Return the number of bytes written.
Sourcepub fn into_inner(self) -> AvroResult<W>
pub fn into_inner(self) -> AvroResult<W>
Return what the Writer
is writing to, consuming the Writer
itself.
NOTE This function forces the written data to be flushed (an implicit
call to flush
is performed).