Crate avrow

Source
Expand description

Avrow is a pure Rust implementation of the Apache Avro specification.

Please refer to the README for an overview. For more details on the spec, head over to the FAQ.

§Using the library

Add avrow to your Cargo.toml:

 [dependencies]
 avrow = "0.2.1"

§A hello world example of reading and writing avro data files

 use avrow::{Reader, Schema, Writer, from_value};
 use std::str::FromStr;
 use anyhow::Error;

 fn main() -> Result<(), Error> {
     // Writing data

     // Create a schema
     let schema = Schema::from_str(r##""null""##)?;
     // Create writer using schema and provide a buffer to write to
     let mut writer = Writer::new(&schema, vec![])?;
     // Write data using write
     writer.write(())?;
     // or serialize via serde
     writer.serialize(())?;
     // retrieve the underlying buffer using the into_inner method.
     let buf = writer.into_inner()?;

     // Reading data

     // Create Reader by providing a Read wrapped version of `buf`
     let reader = Reader::new(buf.as_slice())?;
     // Use iterator for reading data in an idiomatic manner.
     for i in reader {
         // reading values can fail due to decoding errors, so the return value of iterator is a Option<Result<Value>>
         // it allows one to examine the failure reason on the underlying avro reader.
         dbg!(&i);
         // This value can be converted to a native Rust type using from_value method from the serde impl.
         let _: () = from_value(&i)?;
     }

     Ok(())
 }

Modules§

config
This module contains constants and configuration parameters for configuring avro writers and readers.

Macros§

fixed
Convenient macro to create a avro fixed value

Structs§

Header
Header represents the avro datafile header.
Reader
Reader is the primary interface for reading data from an avro datafile.
Record
The Record avro type. Avro records translates to a struct in Rust. Any struct that implements serde’s Serializable trait can be converted to an avro record.
Schema
Represents the avro schema used to write encoded avro data.
Writer
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.
WriterBuilder
Convenient builder struct for configuring and instantiating a Writer.

Enums§

AvrowErr
Errors returned from avrow
Codec
Defines codecs one can use when writing avro data.
Value
Represents an Avro value

Functions§

from_value
from_value is the serde API for deserialization of avro encoded data to native Rust types.
to_value
to_value is the serde API for serialization of Rust types to an avrow::Value