Schema

Enum Schema 

Source
pub enum Schema {
Show 28 variants Null, Boolean, Int, Long, Float, Double, Bytes, String, Array(ArraySchema), Map(MapSchema), Union(UnionSchema), Record(RecordSchema), Enum(EnumSchema), Fixed(FixedSchema), Decimal(DecimalSchema), BigDecimal, Uuid(UuidSchema), Date, TimeMillis, TimeMicros, TimestampMillis, TimestampMicros, TimestampNanos, LocalTimestampMillis, LocalTimestampMicros, LocalTimestampNanos, Duration(FixedSchema), Ref { name: Name, },
}
Expand description

Represents any valid Avro schema More information about Avro schemas can be found in the Avro Specification

Variants§

§

Null

A null Avro schema.

§

Boolean

A boolean Avro schema.

§

Int

An int Avro schema.

§

Long

A long Avro schema.

§

Float

A float Avro schema.

§

Double

A double Avro schema.

§

Bytes

A bytes Avro schema.

Bytes represents a sequence of 8-bit unsigned bytes.

§

String

A string Avro schema.

String represents a unicode character sequence.

§

Array(ArraySchema)

An array Avro schema.

All items will have the same schema.

§

Map(MapSchema)

A map Avro schema.

Keys are always a Schema::String and all values will have the same schema.

§

Union(UnionSchema)

A union Avro schema.

§

Record(RecordSchema)

A record Avro schema.

§

Enum(EnumSchema)

An enum Avro schema.

§

Fixed(FixedSchema)

A fixed Avro schema.

§

Decimal(DecimalSchema)

Logical type which represents Decimal values.

The underlying type is serialized and deserialized as Schema::Bytes or Schema::Fixed.

§

BigDecimal

Logical type which represents Decimal values without predefined scale.

The underlying type is serialized and deserialized as Schema::Bytes

§

Uuid(UuidSchema)

A universally unique identifier, annotating a string, bytes or fixed.

§

Date

Logical type which represents the number of days since the unix epoch.

Serialization format is Schema::Int.

§

TimeMillis

The time of day in number of milliseconds after midnight.

This type has no reference to any calendar, time zone or date in particular.

§

TimeMicros

The time of day in number of microseconds after midnight.

This type has no reference to any calendar, time zone or date in particular.

§

TimestampMillis

An instant in time represented as the number of milliseconds after the UNIX epoch.

§

TimestampMicros

An instant in time represented as the number of microseconds after the UNIX epoch.

§

TimestampNanos

An instant in time represented as the number of nanoseconds after the UNIX epoch.

§

LocalTimestampMillis

An instant in localtime represented as the number of milliseconds after the UNIX epoch.

§

LocalTimestampMicros

An instant in local time represented as the number of microseconds after the UNIX epoch.

§

LocalTimestampNanos

An instant in local time represented as the number of nanoseconds after the UNIX epoch.

§

Duration(FixedSchema)

An amount of time defined by a number of months, days and milliseconds.

§

Ref

A reference to another schema.

Fields

§name: Name

Implementations§

Source§

impl Schema

Source

pub fn union(schemas: Vec<Schema>) -> AvroResult<Schema>

Returns a Schema::Union with the given variants.

§Errors

Will return an error if schemas has duplicate unnamed schemas or if schemas contains a union.

Source

pub fn map(types: Schema) -> SchemaMapBuilder

Returns a Schema::Map with the given types and optional default and custom attributes.

Source

pub fn array(items: Schema) -> SchemaArrayBuilder

Returns a Schema::Array with the given items and optional default and custom attributes.

Source

pub fn enum<I1>(name: Name, symbols: Vec<I1>) -> SchemaEnumBuilder<I1>
where I1: Into<String>,

Returns a Schema::Enum with the given name, symbols and optional aliases, doc, default and custom attributes.

Source

pub fn fixed(name: Name, size: usize) -> SchemaFixedBuilder

Returns a Schema::Fixed with the given name, size and optional aliases, doc and custom attributes.

Source

pub fn record(name: Name) -> SchemaRecordBuilder

Returns a Schema::Record with the given name, size and optional aliases, doc and custom attributes.

Source§

impl Schema

Source

pub fn canonical_form(&self) -> String

Converts self into its Parsing Canonical Form.

Source

pub fn independent_canonical_form( &self, schemata: &[Schema], ) -> Result<String, Error>

Returns the Parsing Canonical Form of self that is self contained (not dependent on any definitions in schemata)

If you require a self contained schema including default and doc attributes, see denormalize.

Source

pub fn fingerprint<D: Digest>(&self) -> SchemaFingerprint

Generate the fingerprint of the schema’s Parsing Canonical Form.

§Example
use apache_avro::rabin::Rabin;
use apache_avro::{Schema, Error};
use md5::Md5;
use sha2::Sha256;

fn main() -> Result<(), Error> {
    let raw_schema = r#"
        {
            "type": "record",
            "name": "test",
            "fields": [
                {"name": "a", "type": "long", "default": 42},
                {"name": "b", "type": "string"}
            ]
        }
    "#;
    let schema = Schema::parse_str(raw_schema)?;
    println!("{}", schema.fingerprint::<Sha256>());
    println!("{}", schema.fingerprint::<Md5>());
    println!("{}", schema.fingerprint::<Rabin>());
    Ok(())
}
Source

pub fn parse_str(input: &str) -> Result<Schema, Error>

Create a Schema from a string representing a JSON Avro schema.

Source

pub fn parse_list( input: impl IntoIterator<Item = impl AsRef<str>>, ) -> AvroResult<Vec<Schema>>

Create an array of Schema’s from a list of named JSON Avro schemas (Record, Enum, and Fixed).

It is allowed that the schemas have cross-dependencies; these will be resolved during parsing.

If two of the input schemas have the same fullname, an Error will be returned.

Source

pub fn parse_str_with_list( schema: &str, schemata: impl IntoIterator<Item = impl AsRef<str>>, ) -> AvroResult<(Schema, Vec<Schema>)>

Create a Schema from a string representing a JSON Avro schema, along with an array of Schema’s from a list of named JSON Avro schemas (Record, Enum, and Fixed).

It is allowed that the schemas have cross-dependencies; these will be resolved during parsing.

If two of the named input schemas have the same fullname, an Error will be returned.

§Arguments
  • schema - the JSON string of the schema to parse
  • schemata - a slice of additional schemas that is used to resolve cross-references
Source

pub fn parse_reader(reader: &mut (impl Read + ?Sized)) -> AvroResult<Schema>

Create a Schema from a reader which implements Read.

Source

pub fn parse(value: &JsonValue) -> AvroResult<Schema>

Parses an Avro schema from JSON.

Source

pub fn custom_attributes(&self) -> Option<&BTreeMap<String, JsonValue>>

Returns the custom attributes (metadata) if the schema supports them.

Source

pub fn is_named(&self) -> bool

Returns whether the schema represents a named type according to the avro specification

Source

pub fn name(&self) -> Option<&Name>

Returns the name of the schema if it has one.

Source

pub fn namespace(&self) -> Namespace

Returns the namespace of the schema if it has one.

Source

pub fn aliases(&self) -> Option<&Vec<Alias>>

Returns the aliases of the schema if it has ones.

Source

pub fn doc(&self) -> Option<&String>

Returns the doc of the schema if it has one.

Source

pub fn denormalize(&mut self, schemata: &[Schema]) -> AvroResult<()>

Remove all external references from the schema.

schemata must contain all externally referenced schemas.

§Errors

Will return a Details::SchemaResolutionError if it fails to find a referenced schema. This will put the schema in a partly denormalized state.

Trait Implementations§

Source§

impl Clone for Schema

Source§

fn clone(&self) -> Schema

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'_enum> From<&'_enum Schema> for SchemaKind

Source§

fn from(val: &'_enum Schema) -> SchemaKind

Converts to this type from the input type.
Source§

impl From<Schema> for SchemaKind

Source§

fn from(val: Schema) -> SchemaKind

Converts to this type from the input type.
Source§

impl IntoDiscriminant for Schema

Source§

type Discriminant = SchemaKind

Enum listing the same variants as this enum but without any data fields
Source§

fn discriminant(&self) -> Self::Discriminant

Source§

impl PartialEq for Schema

Source§

fn eq(&self, other: &Self) -> bool

Assess equality of two Schema based on Parsing Canonical Form.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Schema

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'s> TryFrom<&'s Schema> for ResolvedSchema<'s>

Source§

type Error = Error

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

fn try_from(schema: &'s Schema) -> AvroResult<Self>

Performs the conversion.
Source§

impl TryFrom<Schema> for InnerDecimalSchema

Source§

type Error = Error

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

fn try_from(value: Schema) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Schema

§

impl RefUnwindSafe for Schema

§

impl Send for Schema

§

impl Sync for Schema

§

impl Unpin for Schema

§

impl UnwindSafe for Schema

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.