Struct apache_avro::Writer

source ·
pub struct Writer<'a, W> { /* private fields */ }
Expand description

Main interface for writing Avro formatted values.

Implementations§

source§

impl<'a, W> Writer<'a, W>

source

pub fn builder() -> WriterBuilder<'a, W, ((), (), (), (), (), ())>

Create a builder for building Writer. On the builder, call .schema(...), .writer(...), .codec(...)(optional), .block_size(...)(optional), .marker(...)(optional), .user_metadata(...)(optional) to set the values of the fields. Finally, call .build() to create the instance of Writer.

source§

impl<'a, W: Write> Writer<'a, W>

source

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.

source

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.

source

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.

source

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.

source

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

source

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

source

pub fn schema(&self) -> &'a Schema

Get a reference to the Schema associated to a Writer.

source

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.

source

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.

source

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.

source

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).

source

pub fn extend_ser<I, T: Serialize>(&mut self, values: I) -> AvroResult<usize>where I: IntoIterator<Item = T>,

Extend a Writer with an Iterator of anything implementing the Serialize trait for serde compatibility, 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).

source

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).

source

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.

source

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).

source

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.

Auto Trait Implementations§

§

impl<'a, W> RefUnwindSafe for Writer<'a, W>where W: RefUnwindSafe,

§

impl<'a, W> Send for Writer<'a, W>where W: Send,

§

impl<'a, W> Sync for Writer<'a, W>where W: Sync,

§

impl<'a, W> Unpin for Writer<'a, W>where W: Unpin,

§

impl<'a, W> UnwindSafe for Writer<'a, W>where W: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V