This is an automated email from the ASF dual-hosted git repository. Kriskras99 pushed a commit to branch feat/deprecated_and_docs_cleanup in repository https://gitbox.apache.org/repos/asf/avro-rs.git
commit 29cd9e63f81bcda20ad027da7ad8b503d339071a Author: Kriskras99 <[email protected]> AuthorDate: Mon Nov 9 21:29:50 2026 +0100 feat!: Remove most deprecated items and improve the documentation --- avro/src/bytes.rs | 223 ------------------------------------ avro/src/codec.rs | 3 + avro/src/decimal.rs | 1 + avro/src/documentation/dynamic.rs | 17 +-- avro/src/documentation/primer.rs | 6 +- avro/src/duration.rs | 6 +- avro/src/error.rs | 27 +---- avro/src/lib.rs | 97 +++++----------- avro/src/reader/datum.rs | 95 --------------- avro/src/reader/single_object.rs | 6 + avro/src/schema/mod.rs | 12 -- avro/src/serde/de.rs | 2 +- avro/src/serde/ser.rs | 2 +- avro/src/types.rs | 2 +- avro/src/writer/datum.rs | 49 -------- avro/src/writer/mod.rs | 6 - avro/src/writer/single_object.rs | 16 +-- avro/tests/append_to_existing.rs | 3 +- avro_derive/src/attributes/avro.rs | 5 - avro_derive/src/attributes/serde.rs | 5 - 20 files changed, 58 insertions(+), 525 deletions(-) diff --git a/avro/src/bytes.rs b/avro/src/bytes.rs deleted file mode 100644 index c61f124..0000000 --- a/avro/src/bytes.rs +++ /dev/null @@ -1,223 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//! Deprecated. Use [`apache_avro::serde`] instead. -//! -//! [`apache_avro::serde`](crate::serde) - -#[cfg(doc)] -use crate as apache_avro; - -/// Deprecated. Use [`apache_avro::serde::bytes`] instead. -#[deprecated(since = "0.22.0", note = "Use `apache_avro::serde::bytes` instead")] -pub mod serde_avro_bytes { - #[cfg(doc)] - use crate as apache_avro; - use serde::{Deserializer, Serializer}; - - /// Deprecated. Use [`apache_avro::serde::bytes::serialize`] instead. - #[deprecated( - since = "0.22.0", - note = "Use `apache_avro::serde::bytes::serialize` instead" - )] - pub fn serialize<S>(bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error> - where - S: Serializer, - { - crate::serde::bytes::serialize(bytes, serializer) - } - - /// Deprecated. Use [`apache_avro::serde::bytes::deserialize`] instead. - #[deprecated( - since = "0.22.0", - note = "Use `apache_avro::serde::bytes::deserialize` instead" - )] - pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error> - where - D: Deserializer<'de>, - { - crate::serde::bytes::deserialize(deserializer) - } -} - -/// Deprecated. Use [`apache_avro::serde::bytes_opt`] instead. -/// -/// [`apache_avro::serde::bytes_opt`](crate::serde::bytes_opt) -#[deprecated(since = "0.22.0", note = "Use `apache_avro::serde::bytes_opt` instead")] -pub mod serde_avro_bytes_opt { - #[cfg(doc)] - use crate as apache_avro; - use serde::{Deserializer, Serializer}; - use std::borrow::Borrow; - - /// Deprecated. Use [`apache_avro::serde::bytes_opt::serialize`] instead. - #[deprecated( - since = "0.22.0", - note = "Use `apache_avro::serde::bytes_opt::serialize` instead" - )] - pub fn serialize<S, B>(bytes: &Option<B>, serializer: S) -> Result<S::Ok, S::Error> - where - S: Serializer, - B: Borrow<[u8]> + serde_bytes::Serialize, - { - crate::serde::bytes_opt::serialize(bytes, serializer) - } - - /// Deprecated. Use [`apache_avro::serde::bytes_opt::deserialize`] instead. - #[deprecated( - since = "0.22.0", - note = "Use `apache_avro::serde::bytes_opt::deserialize` instead" - )] - pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Vec<u8>>, D::Error> - where - D: Deserializer<'de>, - { - crate::serde::bytes_opt::deserialize(deserializer) - } -} - -/// Deprecated. Use [`apache_avro::serde::fixed`] instead. -#[deprecated(since = "0.22.0", note = "Use `apache_avro::serde::fixed` instead")] -pub mod serde_avro_fixed { - #[cfg(doc)] - use crate as apache_avro; - use serde::{Deserializer, Serializer}; - - /// Deprecated. Use [`apache_avro::serde::fixed::serialize`] instead. - #[deprecated( - since = "0.22.0", - note = "Use `apache_avro::serde::fixed::serialize` instead" - )] - pub fn serialize<S>(bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error> - where - S: Serializer, - { - crate::serde::fixed::serialize(bytes, serializer) - } - - /// Deprecated. Use [`apache_avro::serde::fixed::deserialize`] instead. - #[deprecated( - since = "0.22.0", - note = "Use `apache_avro::serde::fixed::deserialize` instead" - )] - pub fn deserialize<'de, D, const N: usize>(deserializer: D) -> Result<[u8; N], D::Error> - where - D: Deserializer<'de>, - { - crate::serde::fixed::deserialize(deserializer) - } -} - -/// Deprecated. Use [`apache_avro::serde::fixed_opt`] instead. -#[deprecated(since = "0.22.0", note = "Use `apache_avro::serde::fixed_opt` instead")] -pub mod serde_avro_fixed_opt { - #[cfg(doc)] - use crate as apache_avro; - use serde::{Deserializer, Serializer}; - use std::borrow::Borrow; - - /// Deprecated. Use [`apache_avro::serde::fixed_opt::serialize`] instead. - #[deprecated( - since = "0.22.0", - note = "Use `apache_avro::serde::fixed_opt::serialize` instead" - )] - pub fn serialize<S, B>(bytes: &Option<B>, serializer: S) -> Result<S::Ok, S::Error> - where - S: Serializer, - B: Borrow<[u8]> + serde_bytes::Serialize, - { - crate::serde::fixed_opt::serialize(bytes, serializer) - } - - /// Deprecated. Use [`apache_avro::serde::fixed_opt::deserialize`] instead. - #[deprecated( - since = "0.22.0", - note = "Use `apache_avro::serde::fixed_opt::deserialize` instead" - )] - pub fn deserialize<'de, D, const N: usize>(deserializer: D) -> Result<Option<[u8; N]>, D::Error> - where - D: Deserializer<'de>, - { - crate::serde::fixed_opt::deserialize(deserializer) - } -} - -/// Deprecated. Use [`apache_avro::serde::slice`] instead. -#[deprecated(since = "0.22.0", note = "Use `apache_avro::serde::slice` instead")] -pub mod serde_avro_slice { - #[cfg(doc)] - use crate as apache_avro; - use serde::{Deserializer, Serializer}; - - /// Deprecated. Use [`apache_avro::serde::slice::serialize`] instead. - #[deprecated( - since = "0.22.0", - note = "Use `apache_avro::serde::slice::serialize` instead" - )] - pub fn serialize<S>(bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error> - where - S: Serializer, - { - crate::serde::slice::serialize(bytes, serializer) - } - - /// Deprecated. Use [`apache_avro::serde::slice::deserialize`] instead. - #[deprecated( - since = "0.22.0", - note = "Use `apache_avro::serde::slice::deserialize` instead" - )] - pub fn deserialize<'de, D>(deserializer: D) -> Result<&'de [u8], D::Error> - where - D: Deserializer<'de>, - { - crate::serde::slice::deserialize(deserializer) - } -} - -/// Deprecated. Use [`apache_avro::serde::slice_opt`] instead. -#[deprecated(since = "0.22.0", note = "Use `apache_avro::serde::slice_opt` instead")] -pub mod serde_avro_slice_opt { - #[cfg(doc)] - use crate as apache_avro; - use serde::{Deserializer, Serializer}; - use std::borrow::Borrow; - - /// Deprecated. Use [`apache_avro::serde::slice_opt::serialize`] instead. - #[deprecated( - since = "0.22.0", - note = "Use `apache_avro::serde::slice_opt::serialize` instead" - )] - pub fn serialize<S, B>(bytes: &Option<B>, serializer: S) -> Result<S::Ok, S::Error> - where - S: Serializer, - B: Borrow<[u8]> + serde_bytes::Serialize, - { - crate::serde::slice_opt::serialize(bytes, serializer) - } - - /// Deprecated. Use [`apache_avro::serde::slice_opt::deserialize`] instead. - #[deprecated( - since = "0.22.0", - note = "Use `apache_avro::serde::slice_opt::deserialize` instead" - )] - pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<&'de [u8]>, D::Error> - where - D: Deserializer<'de>, - { - crate::serde::slice_opt::deserialize(deserializer) - } -} diff --git a/avro/src/codec.rs b/avro/src/codec.rs index 77d275e..4b9ed74 100644 --- a/avro/src/codec.rs +++ b/avro/src/codec.rs @@ -255,6 +255,7 @@ impl Codec { pub mod bzip { use bzip2::Compression; + /// Settings for configuring bzip2 compression. #[derive(Clone, Copy, Eq, PartialEq, Debug)] pub struct Bzip2Settings { pub compression_level: u8, @@ -279,6 +280,7 @@ pub mod bzip { #[cfg(feature = "zstandard")] pub mod zstandard { + /// Settings for configuring zstandard compression. #[derive(Clone, Copy, Eq, PartialEq, Debug)] pub struct ZstandardSettings { pub compression_level: u8, @@ -299,6 +301,7 @@ pub mod zstandard { #[cfg(feature = "xz")] pub mod xz { + /// Settings for configuring xz compression. #[derive(Clone, Copy, Eq, PartialEq, Debug)] pub struct XzSettings { pub compression_level: u8, diff --git a/avro/src/decimal.rs b/avro/src/decimal.rs index 997cace..39c3c15 100644 --- a/avro/src/decimal.rs +++ b/avro/src/decimal.rs @@ -20,6 +20,7 @@ use num_bigint::{BigInt, Sign}; use serde::{Deserialize, Serialize, Serializer, de::SeqAccess}; use std::num::NonZero; +/// A decimal as specified in the Avro specification. #[derive(Debug, Clone, Eq)] pub struct Decimal { value: BigInt, diff --git a/avro/src/documentation/dynamic.rs b/avro/src/documentation/dynamic.rs index a6e3088..d224148 100644 --- a/avro/src/documentation/dynamic.rs +++ b/avro/src/documentation/dynamic.rs @@ -228,13 +228,6 @@ //! //! ``` //! use apache_avro::{Codec, DeflateSettings, Reader, Schema, Writer, from_value, types::Record, Error}; -//! use serde::{Deserialize, Serialize}; -//! -//! #[derive(Debug, Deserialize, Serialize)] -//! struct Test { -//! a: i64, -//! b: String, -//! } //! //! fn main() -> Result<(), Error> { //! let raw_schema = r#" @@ -260,18 +253,12 @@ //! //! writer.append_value(record)?; //! -//! let test = Test { -//! a: 27, -//! b: "foo".to_owned(), -//! }; -//! -//! writer.append_ser(test)?; -//! //! let input = writer.into_inner()?; //! let reader = Reader::builder(&input[..]).reader_schema(&schema).build()?; //! //! for record in reader { -//! println!("{:?}", from_value::<Test>(&record?)); +//! let record = record?; +//! println!("{record:?}"); //! } //! Ok(()) //! } diff --git a/avro/src/documentation/primer.rs b/avro/src/documentation/primer.rs index 2efc322..c234f6b 100644 --- a/avro/src/documentation/primer.rs +++ b/avro/src/documentation/primer.rs @@ -78,10 +78,8 @@ //! schema and can therefore not be decoded without the reader knowing **exactly** which schema was //! used to write it. //! -//! This file format can be used via the [`to_avro_datum`](crate::to_avro_datum), [`from_avro_datum`](crate::from_avro_datum), -//! [`to_avro_datum_schemata`](crate::to_avro_datum_schemata), [`from_avro_datum_schemata`](crate::from_avro_datum_schemata), -//! [`from_avro_datum_reader_schemata`](crate::from_avro_datum_reader_schemata), and -//! [`write_avro_datum_ref`](crate::write_avro_datum_ref) functions. +//! This file format can be used via the [`GenericDatumWriter`](crate::writer::datum::GenericDatumWriter) +//! and [`GenericDatumReader`](crate::reader::datum::GenericDatumReader) functions. //! //! #### [Avro JSON](https://avro.apache.org/docs/++version++/specification/#json-encoding) //! Not be confused with the schema definition which is also in JSON. This is the Avro data encoded diff --git a/avro/src/duration.rs b/avro/src/duration.rs index eecfca1..e54a9e5 100644 --- a/avro/src/duration.rs +++ b/avro/src/duration.rs @@ -17,8 +17,7 @@ use serde::{Deserialize, Serialize, de}; -/// A struct representing duration that hides the details of endianness and conversion between -/// platform-native u32 and byte arrays. +/// A duration as specified in the Avro specification. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub struct Duration { months: Months, @@ -26,6 +25,7 @@ pub struct Duration { millis: Millis, } +/// The months part of a duration as specified in the Avro specification. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub struct Months(u32); @@ -51,6 +51,7 @@ impl From<[u8; 4]> for Months { } } +/// The days part of a duration as specified in the Avro specification. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub struct Days(u32); @@ -76,6 +77,7 @@ impl From<[u8; 4]> for Days { } } +/// The milliseconds part of a duration as specified in the Avro specification. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub struct Millis(u32); diff --git a/avro/src/error.rs b/avro/src/error.rs index e7cdcd9..a7d58d1 100644 --- a/avro/src/error.rs +++ b/avro/src/error.rs @@ -15,6 +15,8 @@ // specific language governing permissions and limitations // under the License. +//! Types for dealing with errors. + use crate::{ schema::{Name, RecordSchema, Schema, SchemaKind, UnionSchema}, types::{Value, ValueKind}, @@ -375,10 +377,6 @@ pub enum Details { #[error("Cannot convert u64 to usize: {1}")] ConvertU64ToUsize(#[source] std::num::TryFromIntError, u64), - #[deprecated(since = "0.20.0", note = "This error variant is not generated anymore")] - #[error("Cannot convert u32 to usize: {1}")] - ConvertU32ToUsize(#[source] std::num::TryFromIntError, u32), - #[error("Cannot convert i64 to usize: {1}")] ConvertI64ToUsize(#[source] std::num::TryFromIntError, i64), @@ -433,20 +431,12 @@ pub enum Details { #[error("The decimal precision ({precision}) must be a non-zero positive number")] DecimalPrecisionMuBePositive { precision: usize }, - #[deprecated(since = "0.20.0", note = "This error variant is not generated anymore")] - #[error("Unreadable big decimal sign")] - BigDecimalSign, - #[error("Unreadable length for big decimal inner bytes: {0}")] BigDecimalLen(#[source] Box<Error>), #[error("Unreadable big decimal scale")] BigDecimalScale, - #[deprecated(since = "0.20.0", note = "This error variant is not generated anymore")] - #[error("Unexpected `type` {0} variant for `logicalType`")] - GetLogicalTypeVariant(serde_json::Value), - #[error("No `type` field found for `logicalType`")] GetLogicalTypeField, @@ -545,19 +535,6 @@ pub enum Details { #[error("Expected a string for the `{0}` field, got a {1}")] GetStringInvalidType(&'static str, &'static str), - #[deprecated(since = "0.22.0", note = "This error variant is not generated anymore")] - #[error("Fixed schema's default value length ({0}) does not match its size ({1})")] - FixedDefaultLenSizeMismatch(usize, u64), - - #[deprecated(since = "0.20.0", note = "This error variant is not generated anymore")] - #[error("Failed to compress with flate: {0}")] - DeflateCompress(#[source] std::io::Error), - - // no longer possible after migration from libflate to miniz_oxide - #[deprecated(since = "0.19.0", note = "This error can no longer occur")] - #[error("Failed to finish flate compressor: {0}")] - DeflateCompressFinish(#[source] std::io::Error), - #[error("Failed to decompress with flate: {0}")] DeflateDecompress(#[source] std::io::Error), diff --git a/avro/src/lib.rs b/avro/src/lib.rs index 3f50989..afe534c 100644 --- a/avro/src/lib.rs +++ b/avro/src/lib.rs @@ -54,7 +54,6 @@ #![cfg_attr(docsrs, allow(internal_features))] mod bigdecimal; -mod bytes; mod codec; mod decimal; mod decode; @@ -76,46 +75,41 @@ pub mod util; pub mod validator; pub mod writer; -#[expect(deprecated)] +// Re-export types from private module pub use crate::{ bigdecimal::BigDecimal, - bytes::{ - serde_avro_bytes, serde_avro_bytes_opt, serde_avro_fixed, serde_avro_fixed_opt, - serde_avro_slice, serde_avro_slice_opt, - }, + codec::{Codec, DeflateSettings}, + decimal::Decimal, + duration::{Days, Duration, Millis, Months}, }; + +// Re-export types from private modules that need to be behind feature gates #[cfg(feature = "bzip")] -pub use codec::bzip::Bzip2Settings; +pub use crate::codec::bzip::Bzip2Settings; #[cfg(feature = "xz")] -pub use codec::xz::XzSettings; +pub use crate::codec::xz::XzSettings; #[cfg(feature = "zstandard")] -pub use codec::zstandard::ZstandardSettings; -pub use codec::{Codec, DeflateSettings}; -pub use decimal::Decimal; -pub use duration::{Days, Duration, Millis, Months}; -pub use error::Error; -#[expect( - deprecated, - reason = "Still need to export it until we remove it completely" -)] -pub use reader::{ - Reader, - datum::{from_avro_datum, from_avro_datum_reader_schemata, from_avro_datum_schemata}, - read_marker, - single_object::{GenericSingleObjectReader, SpecificSingleObjectReader}, +pub use crate::codec::zstandard::ZstandardSettings; + +// Re-exports that are available at their respective paths but are made available in the root for +// convenience. +#[doc(inline)] +pub use crate::{ + error::Error, + reader::{ + Reader, + single_object::{GenericSingleObjectReader, SpecificSingleObjectReader}, + }, + schema::Schema, + serde::{AvroSchema, AvroSchemaComponent, from_value, to_value}, + writer::{ + Clearable, Writer, WriterBuilder, + single_object::{GenericSingleObjectWriter, SpecificSingleObjectWriter}, + }, }; -pub use schema::Schema; -pub use serde::{AvroSchema, AvroSchemaComponent, from_value, to_value}; + +// Re-exports from other crates pub use uuid::Uuid; -#[expect( - deprecated, - reason = "Still need to export it until we remove it completely" -)] -pub use writer::{ - Clearable, Writer, WriterBuilder, - datum::{to_avro_datum, to_avro_datum_schemata, write_avro_datum_ref}, - single_object::{GenericSingleObjectWriter, SpecificSingleObjectWriter}, -}; #[cfg(feature = "derive")] pub use apache_avro_derive::AvroSchema; @@ -123,43 +117,6 @@ pub use apache_avro_derive::AvroSchema; /// A convenience type alias for `Result`s with `Error`s. pub type AvroResult<T> = Result<T, Error>; -/// Set the maximum number of bytes that can be allocated when decoding data. -/// -/// This function only changes the setting once. On subsequent calls the value will stay the same -/// as the first time it is called. It is automatically called on first allocation and defaults to -/// [`util::DEFAULT_MAX_ALLOCATION_BYTES`]. -/// -/// # Returns -/// The configured maximum, which might be different from what the function was called with if the -/// value was already set before. -#[deprecated( - since = "0.21.0", - note = "Please use apache_avro::util::max_allocation_bytes" -)] -pub fn max_allocation_bytes(num_bytes: usize) -> usize { - util::max_allocation_bytes(num_bytes) -} - -/// Set whether the serializer and deserializer should indicate to types that the format is human-readable. -/// -/// This function only changes the setting once. On subsequent calls the value will stay the same -/// as the first time it is called. It is automatically called on first allocation and defaults to -/// [`util::DEFAULT_SERDE_HUMAN_READABLE`]. -/// -/// *NOTE*: Changing this setting can change the output of [`from_value`] and the -/// accepted input of [`to_value`]. -/// -/// # Returns -/// The configured human-readable value, which might be different from what the function was called -/// with if the value was already set before. -#[deprecated( - since = "0.21.0", - note = "Please use apache_avro::util::set_serde_human_readable" -)] -pub fn set_serde_human_readable(human_readable: bool) -> bool { - util::set_serde_human_readable(human_readable) -} - #[cfg(test)] mod tests { use crate::{ diff --git a/avro/src/reader/datum.rs b/avro/src/reader/datum.rs index 783ca3d..8d524b2 100644 --- a/avro/src/reader/datum.rs +++ b/avro/src/reader/datum.rs @@ -210,101 +210,6 @@ impl<T: AvroSchema + DeserializeOwned> SpecificDatumReader<T> { } } -/// Deprecated. -/// -/// This is equivalent to -/// ```ignore -/// GenericDatumReader::builder(writer_schema) -/// .maybe_reader_schema(reader_schema) -/// .build()? -/// .read_value(reader) -/// ``` -/// -/// Decode a `Value` encoded in Avro format given its `Schema` and anything implementing `io::Read` -/// to read from. -/// -/// In case a reader `Schema` is provided, schema resolution will also be performed. -/// -/// **NOTE** This function has a quite small niche of usage and does NOT take care of reading the -/// header and consecutive data blocks; use [`Reader`](struct.Reader.html) if you don't know what -/// you are doing, instead. -#[deprecated(since = "0.22.0", note = "Use `GenericDatumReader` instead")] -pub fn from_avro_datum<R: Read>( - writer_schema: &Schema, - reader: &mut R, - reader_schema: Option<&Schema>, -) -> AvroResult<Value> { - GenericDatumReader::builder(writer_schema) - .maybe_reader_schema(reader_schema) - .build()? - .read_value(reader) -} - -/// Deprecated. -/// -/// This is equivalent to -/// ```ignore -/// GenericDatumReader::builder(writer_schema) -/// .writer_schemata(writer_schemata)? -/// .maybe_reader_schema(reader_schema) -/// .build()? -/// .read_value(reader) -/// ``` -/// -/// Decode a `Value` from raw Avro data. -/// -/// If the writer schema is incomplete, i.e. contains `Schema::Ref`s then it will use the provided -/// schemata to resolve any dependencies. -/// -/// When a reader `Schema` is provided, schema resolution will also be performed. -#[deprecated(since = "0.22.0", note = "Use `GenericDatumReader` instead")] -pub fn from_avro_datum_schemata<R: Read>( - writer_schema: &Schema, - writer_schemata: Vec<&Schema>, - reader: &mut R, - reader_schema: Option<&Schema>, -) -> AvroResult<Value> { - GenericDatumReader::builder(writer_schema) - .writer_schemata(writer_schemata)? - .maybe_reader_schema(reader_schema) - .build()? - .read_value(reader) -} - -/// Deprecated. -/// -/// This is equivalent to -/// ```ignore -/// GenericDatumReader::builder(writer_schema) -/// .writer_schemata(writer_schemata)? -/// .maybe_reader_schema(reader_schema) -/// .reader_schemata(reader_schemata)? -/// .build()? -/// .read_value(reader) -/// ``` -/// -/// Decode a `Value` from raw Avro data. -/// -/// If the writer schema is incomplete, i.e. contains `Schema::Ref`s then it will use the provided -/// schemata to resolve any dependencies. -/// -/// When a reader `Schema` is provided, schema resolution will also be performed. -#[deprecated(since = "0.22.0", note = "Use `GenericDatumReader` instead")] -pub fn from_avro_datum_reader_schemata<R: Read>( - writer_schema: &Schema, - writer_schemata: Vec<&Schema>, - reader: &mut R, - reader_schema: Option<&Schema>, - reader_schemata: Vec<&Schema>, -) -> AvroResult<Value> { - GenericDatumReader::builder(writer_schema) - .writer_schemata(writer_schemata)? - .maybe_reader_schema(reader_schema) - .reader_schemata(reader_schemata)? - .build()? - .read_value(reader) -} - #[cfg(test)] mod tests { use apache_avro_test_helper::TestResult; diff --git a/avro/src/reader/single_object.rs b/avro/src/reader/single_object.rs index 253cac3..73e5557 100644 --- a/avro/src/reader/single_object.rs +++ b/avro/src/reader/single_object.rs @@ -31,6 +31,9 @@ use crate::{ util::is_human_readable, }; +/// Read `Value`s from a single object encoding. +/// +/// Use [`SpecificSingleObjectReader`] if you need to deserialize into Rust types. pub struct GenericSingleObjectReader { write_schema: ResolvedOwnedSchema, expected_header: Vec<u8>, @@ -96,6 +99,9 @@ impl GenericSingleObjectReader { } } +/// Read Rust types from a single object encoding. +/// +/// Use [`GenericSingleObjectReader`] if you need `Value`s that are not linked to a type. pub struct SpecificSingleObjectReader<T> where T: AvroSchema, diff --git a/avro/src/schema/mod.rs b/avro/src/schema/mod.rs index 0f4b129..6a254a6 100644 --- a/avro/src/schema/mod.rs +++ b/avro/src/schema/mod.rs @@ -230,18 +230,6 @@ impl SchemaKind { | SchemaKind::String, ) } - - #[deprecated(since = "0.22.0", note = "Use Schema::is_named instead")] - pub fn is_named(self) -> bool { - matches!( - self, - SchemaKind::Record - | SchemaKind::Enum - | SchemaKind::Fixed - | SchemaKind::Ref - | SchemaKind::Duration - ) - } } impl From<&types::Value> for SchemaKind { diff --git a/avro/src/serde/de.rs b/avro/src/serde/de.rs index 52f9229..d8f9485 100644 --- a/avro/src/serde/de.rs +++ b/avro/src/serde/de.rs @@ -939,7 +939,7 @@ impl<'de> de::Deserializer<'de> for StringDeserializer { } } -/// Interpret a `Value` as an instance of type `D`. +/// Deserialize a `Value` into a type implementing `Deserialize` type. /// /// This conversion can fail if the structure of the `Value` does not match the /// structure expected by `D`. diff --git a/avro/src/serde/ser.rs b/avro/src/serde/ser.rs index bd41a56..fe09440 100644 --- a/avro/src/serde/ser.rs +++ b/avro/src/serde/ser.rs @@ -473,7 +473,7 @@ impl ser::SerializeStructVariant for StructVariantSerializer { } } -/// Interpret a serializeable instance as a `Value`. +/// Serialize a type implementing `Serialize` into a `Value`. /// /// This conversion can fail if the value is not valid as per the Avro specification. /// e.g: `HashMap` with non-string keys. diff --git a/avro/src/types.rs b/avro/src/types.rs index b65f2ff..0584e76 100644 --- a/avro/src/types.rs +++ b/avro/src/types.rs @@ -189,7 +189,7 @@ where // FIXME: this is incorrect in case first type in union is not "none" Self::Union( value.is_some() as u32, - Box::new(value.map_or_else(|| Self::Null, Into::into)), + Box::new(value.map_or(Self::Null, Into::into)), ) } } diff --git a/avro/src/writer/datum.rs b/avro/src/writer/datum.rs index 2df0a0c..5164293 100644 --- a/avro/src/writer/datum.rs +++ b/avro/src/writer/datum.rs @@ -169,29 +169,6 @@ impl GenericDatumWriter<'_> { } } -/// Deprecated. Use [`GenericDatumWriter`] instead. -/// -/// This is equivalent to: -/// ```ignore -/// GenericDatumWriter::builder(schema) -/// .build()? -/// .write_value_to_vec(value) -/// ``` -/// -/// Encode a value into raw Avro data, also performs schema validation. -/// -/// **NOTE**: This function has a quite small niche of usage and does NOT generate headers and sync -/// markers; use [`Writer`] to be fully Avro-compatible if you don't know what -/// you are doing, instead. -/// -/// [`Writer`]: crate::Writer -#[deprecated(since = "0.22.0", note = "Use GenericDatumWriter instead")] -pub fn to_avro_datum<T: Into<Value>>(schema: &Schema, value: T) -> AvroResult<Vec<u8>> { - GenericDatumWriter::builder(schema) - .build()? - .write_value_to_vec(value) -} - /// Write the referenced [Serialize]able object to the provided [Write] object. /// /// It is recommended to use [`GenericDatumWriter`] instead. @@ -217,32 +194,6 @@ pub fn write_avro_datum_ref<T: Serialize, W: Write>( data.serialize(SchemaAwareSerializer::new(writer, schema, config)?) } -/// Deprecated. Use [`GenericDatumWriter`] instead. -/// -/// This is equivalent to: -/// ```ignore -/// GenericDatumWriter::builder(schema) -/// .schemata(schemata)? -/// .build()? -/// .write_value_to_vec(value) -/// ``` -/// -/// Encode a value into raw Avro data, also performs schema validation. -/// -/// If the provided `schema` is incomplete then its dependencies must be -/// provided in `schemata` -#[deprecated(since = "0.22.0", note = "Use GenericDatumWriter instead")] -pub fn to_avro_datum_schemata<T: Into<Value>>( - schema: &Schema, - schemata: Vec<&Schema>, - value: T, -) -> AvroResult<Vec<u8>> { - GenericDatumWriter::builder(schema) - .schemata(schemata)? - .build()? - .write_value_to_vec(value) -} - #[cfg(test)] mod tests { use apache_avro_test_helper::TestResult; diff --git a/avro/src/writer/mod.rs b/avro/src/writer/mod.rs index efe4337..3a2e475 100644 --- a/avro/src/writer/mod.rs +++ b/avro/src/writer/mod.rs @@ -191,12 +191,6 @@ impl<'a, W: Write> Writer<'a, W> { self.schema } - /// Deprecated. Use [`Writer::append_value`] instead. - #[deprecated(since = "0.22.0", note = "Use `Writer::append_value` instead")] - pub fn append<T: Into<Value>>(&mut self, value: T) -> AvroResult<usize> { - self.append_value(value) - } - /// Append a value to the `Writer`, also performs schema validation. /// /// Returns the number of bytes written (it might be 0, see below). diff --git a/avro/src/writer/single_object.rs b/avro/src/writer/single_object.rs index 8df3f7a..d71d908 100644 --- a/avro/src/writer/single_object.rs +++ b/avro/src/writer/single_object.rs @@ -33,9 +33,9 @@ use crate::{ types::Value, }; -/// Writer that encodes messages according to the single object encoding v1 spec -/// Uses an API similar to the current File Writer -/// Writes all object bytes at once, and drains internal buffer +/// Encode `Value`s to the single object encoding. +/// +/// Use [`SpecificSingleObjectWriter`] if you need to serialize Rust types. pub struct GenericSingleObjectWriter { buffer: Vec<u8>, resolved: ResolvedOwnedSchema, @@ -93,7 +93,9 @@ impl GenericSingleObjectWriter { } } -/// Writer that encodes messages according to the single object encoding v1 spec +/// Encode Rust types to the single object encoding. +/// +/// Use [`GenericSingleObjectWriter`] if you need to serialize `Value`s that are not linked to a type. #[derive(Builder)] pub struct SpecificSingleObjectWriter<T> where @@ -155,12 +157,6 @@ where _model: PhantomData, }) } - - /// Deprecated. Use [`SpecificSingleObjectWriter::new`] instead. - #[deprecated(since = "0.22.0", note = "Use new() instead")] - pub fn with_capacity(_buffer_cap: usize) -> AvroResult<Self> { - Self::new() - } } impl<T> SpecificSingleObjectWriter<T> diff --git a/avro/tests/append_to_existing.rs b/avro/tests/append_to_existing.rs index 4e2f79b..45d1c81 100644 --- a/avro/tests/append_to_existing.rs +++ b/avro/tests/append_to_existing.rs @@ -16,7 +16,8 @@ // under the License. use apache_avro::{ - AvroResult, Reader, Schema, Writer, read_marker, + AvroResult, Reader, Schema, Writer, + reader::read_marker, types::{Record, Value}, }; use apache_avro_test_helper::TestResult; diff --git a/avro_derive/src/attributes/avro.rs b/avro_derive/src/attributes/avro.rs index 5b626e8..bc8b5ef 100644 --- a/avro_derive/src/attributes/avro.rs +++ b/avro_derive/src/attributes/avro.rs @@ -21,11 +21,6 @@ //! Although a user will mostly use the Serde attributes, there are some Avro specific attributes //! a user can use. These add extra metadata to the generated schema. -// `darling` generates `field: field` for `#[darling(multiple)]` fields using the field's own -// span, which Clippy 1.99+ reports as `redundant_field_names` on the struct definition. -// TODO: Remove once https://github.com/TedDriggs/darling/pull/441 is released -#![expect(clippy::redundant_field_names)] - use crate::attributes::FieldDefault; use crate::case::RenameRule; use darling::FromMeta; diff --git a/avro_derive/src/attributes/serde.rs b/avro_derive/src/attributes/serde.rs index 1843a48..f8429e1 100644 --- a/avro_derive/src/attributes/serde.rs +++ b/avro_derive/src/attributes/serde.rs @@ -25,11 +25,6 @@ //! //! If Serde adds new attributes they need to be added here too. -// `darling` generates `field: field` for `#[darling(multiple)]` fields using the field's own -// span, which Clippy 1.99+ reports as `redundant_field_names` on the struct definition. -// TODO: Remove once https://github.com/TedDriggs/darling/pull/441 is released -#![expect(clippy::redundant_field_names)] - use darling::{FromAttributes, FromMeta}; use syn::Expr;
