From 287bb15ca9fd2a57a4a8de4b0bd32d4bb22d7f96 Mon Sep 17 00:00:00 2001 From: Lachlan Deakin Date: Wed, 1 Jan 2025 09:27:40 +1100 Subject: [PATCH] feat: make `Any` a supertrait of partial encoder/decoder traits (#109) * fix: cleanup unnecessary lifetime constraints in partial decoders * refactor: make `{Array,Bytes}PartialDecoderCache` private * fix: remove BytesPartialDecoderCache lifetime constraint * feat: make `Any` a supertrait of partial encoder/decoder traits * fix changelog --- CHANGELOG.md | 1 + zarrs/src/array/codec.rs | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebfac956..5b0edbf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - **Breaking**: Seal `Array` extension traits: `ArraySharded[Readable]Ext` and `ArrayChunkCacheExt` - **Breaking**: Make `{Array,Bytes}PartialDecoderCache` private +- **Breaking**: Make `Any` a supertrait of partial encoder/decoder traits ### Fixed - Cleanup unnecessary lifetime constraints in partial decoders diff --git a/zarrs/src/array/codec.rs b/zarrs/src/array/codec.rs index 9a67bcca..12d09bb7 100644 --- a/zarrs/src/array/codec.rs +++ b/zarrs/src/array/codec.rs @@ -90,6 +90,7 @@ use crate::{ #[cfg(feature = "async")] use crate::storage::AsyncReadableStorage; +use std::any::Any; use std::borrow::Cow; use std::sync::Arc; @@ -241,7 +242,7 @@ pub trait ArrayCodecTraits: CodecTraits { } /// Partial bytes decoder traits. -pub trait BytesPartialDecoderTraits: Send + Sync { +pub trait BytesPartialDecoderTraits: Any + Send + Sync { /// Partially decode bytes. /// /// Returns [`None`] if partial decoding of the input handle returns [`None`]. @@ -288,7 +289,7 @@ pub trait BytesPartialDecoderTraits: Send + Sync { #[cfg(feature = "async")] /// Asynchronous partial bytes decoder traits. #[async_trait::async_trait] -pub trait AsyncBytesPartialDecoderTraits: Send + Sync { +pub trait AsyncBytesPartialDecoderTraits: Any + Send + Sync { /// Partially decode bytes. /// /// Returns [`None`] if partial decoding of the input handle returns [`None`]. @@ -333,7 +334,7 @@ pub trait AsyncBytesPartialDecoderTraits: Send + Sync { } /// Partial array decoder traits. -pub trait ArrayPartialDecoderTraits: Send + Sync { +pub trait ArrayPartialDecoderTraits: Any + Send + Sync { /// Return the data type of the partial decoder. fn data_type(&self) -> &DataType; @@ -394,7 +395,7 @@ pub trait ArrayPartialDecoderTraits: Send + Sync { } /// Partial array encoder traits. -pub trait ArrayPartialEncoderTraits: Send + Sync { +pub trait ArrayPartialEncoderTraits: Any + Send + Sync { /// Erase the chunk. /// /// # Errors @@ -413,7 +414,7 @@ pub trait ArrayPartialEncoderTraits: Send + Sync { } /// Partial bytes encoder traits. -pub trait BytesPartialEncoderTraits: Send + Sync { +pub trait BytesPartialEncoderTraits: Any + Send + Sync { /// Erase the chunk. /// /// # Errors @@ -434,7 +435,7 @@ pub trait BytesPartialEncoderTraits: Send + Sync { #[cfg(feature = "async")] /// Asynchronous partial array decoder traits. #[async_trait::async_trait] -pub trait AsyncArrayPartialDecoderTraits: Send + Sync { +pub trait AsyncArrayPartialDecoderTraits: Any + Send + Sync { /// Return the data type of the partial decoder. fn data_type(&self) -> &DataType; @@ -863,7 +864,7 @@ pub trait BytesToBytesCodecTraits: CodecTraits + core::fmt::Debug { // TODO: Async partial encoder } -impl BytesPartialDecoderTraits for std::io::Cursor<&[u8]> { +impl BytesPartialDecoderTraits for std::io::Cursor<&'static [u8]> { fn partial_decode( &self, decoded_regions: &[ByteRange], @@ -878,7 +879,7 @@ impl BytesPartialDecoderTraits for std::io::Cursor<&[u8]> { } } -impl BytesPartialDecoderTraits for std::io::Cursor> { +impl BytesPartialDecoderTraits for std::io::Cursor> { fn partial_decode( &self, decoded_regions: &[ByteRange], @@ -910,7 +911,7 @@ impl BytesPartialDecoderTraits for std::io::Cursor> { #[cfg(feature = "async")] #[async_trait::async_trait] -impl AsyncBytesPartialDecoderTraits for std::io::Cursor<&[u8]> { +impl AsyncBytesPartialDecoderTraits for std::io::Cursor<&'static [u8]> { async fn partial_decode( &self, decoded_regions: &[ByteRange], @@ -927,7 +928,7 @@ impl AsyncBytesPartialDecoderTraits for std::io::Cursor<&[u8]> { #[cfg(feature = "async")] #[async_trait::async_trait] -impl AsyncBytesPartialDecoderTraits for std::io::Cursor> { +impl AsyncBytesPartialDecoderTraits for std::io::Cursor> { async fn partial_decode( &self, decoded_regions: &[ByteRange],