pub struct Writer<'a, W: Write> { /* private fields */ }Expand description
Main interface for writing Avro formatted values.
It is critical to call flush before Writer<W> is dropped. Though dropping will attempt to flush
the contents of the buffer, any errors that happen in the process of dropping will be ignored.
Calling flush ensures that the buffer is empty and thus dropping will not even attempt file operations.
Implementations§
Source§impl<'a, W: Write> Writer<'a, W>
impl<'a, W: Write> Writer<'a, W>
Sourcepub fn builder() -> WriterBuilder<'a, W>
pub fn builder() -> WriterBuilder<'a, W>
Create an instance of Writer using the builder syntax
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 with_schemata(
schema: &'a Schema,
schemata: Vec<&'a Schema>,
writer: W,
codec: Codec,
) -> Self
pub fn with_schemata( schema: &'a Schema, schemata: Vec<&'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.
If the schema is incomplete, i.e. contains Schema::Refs then all dependencies must
be provided in schemata.
Sourcepub fn append_to(schema: &'a Schema, writer: W, marker: [u8; 16]) -> Self
pub fn append_to(schema: &'a Schema, writer: W, marker: [u8; 16]) -> Self
Creates a Writer that will append values to already populated
std::io::Write using the provided marker
No compression Codec will be used.
Sourcepub fn append_to_with_codec(
schema: &'a Schema,
writer: W,
codec: Codec,
marker: [u8; 16],
) -> Self
pub fn append_to_with_codec( schema: &'a Schema, writer: W, codec: Codec, marker: [u8; 16], ) -> Self
Creates a Writer that will append values to already populated
std::io::Write using the provided marker
Sourcepub fn append_to_with_codec_schemata(
schema: &'a Schema,
schemata: Vec<&'a Schema>,
writer: W,
codec: Codec,
marker: [u8; 16],
) -> Self
pub fn append_to_with_codec_schemata( schema: &'a Schema, schemata: Vec<&'a Schema>, writer: W, codec: Codec, marker: [u8; 16], ) -> Self
Creates a Writer that will append values to already populated
std::io::Write using the provided marker
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.
Returns 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.
Returns 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.
Returns 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.
Returns 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.
Returns 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 to the inner Writer.
Call this function to make sure all the content has been written before releasing the Writer.
This will also write the header if it wasn’t written yet and hasn’t been disabled using
WriterBuilder::has_header.
Returns 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).
Sourcepub fn get_ref(&self) -> &W
pub fn get_ref(&self) -> &W
Gets a reference to the underlying writer.
NOTE: There is likely data still in the buffer. To have all the data
in the writer call flush first.
Sourcepub fn get_mut(&mut self) -> &mut W
pub fn get_mut(&mut self) -> &mut W
Gets a mutable reference to the underlying writer.
It is inadvisable to directly write to the underlying writer.
NOTE: There is likely data still in the buffer. To have all the data
in the writer call flush first.
Sourcepub fn add_user_metadata<T: AsRef<[u8]>>(
&mut self,
key: String,
value: T,
) -> AvroResult<()>
pub fn add_user_metadata<T: AsRef<[u8]>>( &mut self, key: String, value: T, ) -> AvroResult<()>
Adds custom metadata to the file. This method could be used only before adding the first record to the writer.