From 58b648f77bcd31e0168f75e1c6a2019c35c7f045 Mon Sep 17 00:00:00 2001 From: Lachlan Deakin Date: Tue, 24 Dec 2024 10:14:20 +1100 Subject: [PATCH] fix: remove BytesPartialDecoderCache lifetime constraint --- .../codec/bytes_partial_decoder_cache.rs | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/zarrs/src/array/codec/bytes_partial_decoder_cache.rs b/zarrs/src/array/codec/bytes_partial_decoder_cache.rs index d3d6cc77..b584e054 100644 --- a/zarrs/src/array/codec/bytes_partial_decoder_cache.rs +++ b/zarrs/src/array/codec/bytes_partial_decoder_cache.rs @@ -1,6 +1,6 @@ //! A cache for partial decoders. -use std::{borrow::Cow, marker::PhantomData}; +use std::borrow::Cow; use crate::{ array::RawBytes, @@ -13,12 +13,11 @@ use super::{BytesPartialDecoderTraits, CodecError, CodecOptions}; use super::AsyncBytesPartialDecoderTraits; /// A cache for a [`BytesPartialDecoderTraits`] partial decoder. -pub(crate) struct BytesPartialDecoderCache<'a> { +pub(crate) struct BytesPartialDecoderCache { cache: Option>, - phantom: PhantomData<&'a ()>, } -impl<'a> BytesPartialDecoderCache<'a> { +impl BytesPartialDecoderCache { /// Create a new partial decoder cache. /// /// # Errors @@ -30,10 +29,7 @@ impl<'a> BytesPartialDecoderCache<'a> { let cache = input_handle .partial_decode(&[ByteRange::FromStart(0, None)], options)? .map(|mut bytes| bytes.remove(0).into_owned()); - Ok(Self { - cache, - phantom: PhantomData, - }) + Ok(Self { cache }) } #[cfg(feature = "async")] @@ -44,19 +40,16 @@ impl<'a> BytesPartialDecoderCache<'a> { pub(crate) async fn async_new( input_handle: &dyn AsyncBytesPartialDecoderTraits, options: &CodecOptions, - ) -> Result, CodecError> { + ) -> Result { let cache = input_handle .partial_decode(&[ByteRange::FromStart(0, None)], options) .await? .map(|mut bytes| bytes.remove(0).into_owned()); - Ok(Self { - cache, - phantom: PhantomData, - }) + Ok(Self { cache }) } } -impl BytesPartialDecoderTraits for BytesPartialDecoderCache<'_> { +impl BytesPartialDecoderTraits for BytesPartialDecoderCache { fn partial_decode( &self, decoded_regions: &[ByteRange], @@ -77,7 +70,7 @@ impl BytesPartialDecoderTraits for BytesPartialDecoderCache<'_> { #[cfg(feature = "async")] #[async_trait::async_trait] -impl AsyncBytesPartialDecoderTraits for BytesPartialDecoderCache<'_> { +impl AsyncBytesPartialDecoderTraits for BytesPartialDecoderCache { async fn partial_decode( &self, decoded_regions: &[ByteRange],