Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make Any a supertrait of partial encoder/decoder traits #109

Merged
merged 6 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions zarrs/src/array/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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`].
Expand Down Expand Up @@ -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`].
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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],
Expand All @@ -878,7 +879,7 @@ impl BytesPartialDecoderTraits for std::io::Cursor<&[u8]> {
}
}

impl BytesPartialDecoderTraits for std::io::Cursor<RawBytes<'_>> {
impl BytesPartialDecoderTraits for std::io::Cursor<RawBytes<'static>> {
fn partial_decode(
&self,
decoded_regions: &[ByteRange],
Expand Down Expand Up @@ -910,7 +911,7 @@ impl BytesPartialDecoderTraits for std::io::Cursor<Vec<u8>> {

#[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],
Expand All @@ -927,7 +928,7 @@ impl AsyncBytesPartialDecoderTraits for std::io::Cursor<&[u8]> {

#[cfg(feature = "async")]
#[async_trait::async_trait]
impl AsyncBytesPartialDecoderTraits for std::io::Cursor<RawBytes<'_>> {
impl AsyncBytesPartialDecoderTraits for std::io::Cursor<RawBytes<'static>> {
async fn partial_decode(
&self,
decoded_regions: &[ByteRange],
Expand Down
Loading