Skip to content

Commit

Permalink
fix: seal Array extension traits (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
LDeakin authored Dec 31, 2024
1 parent 751a2dd commit 9bb5fea
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- **Breaking**: Seal `Array` extension traits: `ArraySharded[Readable]Ext` and `ArrayChunkCacheExt`

## [0.18.3] - 2024-12-30

### Added
Expand Down
10 changes: 9 additions & 1 deletion zarrs/src/array/array_sharded_ext.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{codec::ShardingCodecConfiguration, Array, ArrayShape, ChunkGrid, ChunkShape};

/// An [`Array`] extension trait to simplify working with arrays using the `sharding_indexed` codec.
pub trait ArrayShardedExt {
pub trait ArrayShardedExt: private::Sealed {
/// Returns true if the array to bytes codec of the array is `sharding_indexed`.
fn is_sharded(&self) -> bool;

Expand Down Expand Up @@ -86,3 +86,11 @@ impl<TStorage: ?Sized> ArrayShardedExt for Array<TStorage> {
}
}
}

mod private {
use super::Array;

pub trait Sealed {}

impl<TStorage: ?Sized> Sealed for Array<TStorage> {}
}
12 changes: 11 additions & 1 deletion zarrs/src/array/array_sync_sharded_readable_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ impl ArrayShardedReadableExtCache {
///
/// Sharding indexes are cached in a [`ArrayShardedReadableExtCache`] enabling faster retrieval.
// TODO: Add default methods? Or change to options: Option<&CodecOptions>? Should really do this for array (breaking)...
pub trait ArrayShardedReadableExt<TStorage: ?Sized + ReadableStorageTraits + 'static> {
pub trait ArrayShardedReadableExt<TStorage: ?Sized + ReadableStorageTraits + 'static>:
private::Sealed
{
/// Read and decode the inner chunk at `chunk_indices` into its bytes.
///
/// See [`Array::retrieve_chunk_opt`].
Expand Down Expand Up @@ -472,6 +474,14 @@ impl<TStorage: ?Sized + ReadableStorageTraits + 'static> ArrayShardedReadableExt
}
}

mod private {
use super::{Array, ReadableStorageTraits};

pub trait Sealed {}

impl<TStorage: ?Sized + ReadableStorageTraits + 'static> Sealed for Array<TStorage> {}
}

#[cfg(test)]
mod tests {
use std::sync::Arc;
Expand Down
12 changes: 11 additions & 1 deletion zarrs/src/array/chunk_cache/array_chunk_cache_ext_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ use super::{ChunkCache, ChunkCacheType};
/// An [`Array`] extension trait to support reading with a chunk cache.
///
/// Note that these methods never perform partial decoding and always fully decode chunks intersected that are not in the cache.
pub trait ArrayChunkCacheExt<TStorage: ?Sized + ReadableStorageTraits + 'static> {
pub trait ArrayChunkCacheExt<TStorage: ?Sized + ReadableStorageTraits + 'static>:
private::Sealed
{
/// Cached variant of [`retrieve_chunk_opt`](Array::retrieve_chunk_opt).
#[allow(clippy::missing_errors_doc)]
fn retrieve_chunk_opt_cached<CT: ChunkCacheType>(
Expand Down Expand Up @@ -454,3 +456,11 @@ impl<TStorage: ?Sized + ReadableStorageTraits + 'static> ArrayChunkCacheExt<TSto
crate::array::elements_to_ndarray(array_subset.shape(), elements)
}
}

mod private {
use super::{Array, ReadableStorageTraits};

pub trait Sealed {}

impl<TStorage: ?Sized + ReadableStorageTraits + 'static> Sealed for Array<TStorage> {}
}

0 comments on commit 9bb5fea

Please sign in to comment.