diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef8f2644..702dea6e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,4 +23,4 @@ jobs: - run: cargo check # default features - run: cargo check --no-default-features - run: cargo fmt --all -- --check - - run: cargo clippy -- -D warnings + - run: cargo clippy --all-features -- -D warnings diff --git a/BUILD.md b/BUILD.md index 7c812d7e..61289b2d 100644 --- a/BUILD.md +++ b/BUILD.md @@ -10,15 +10,15 @@ cargo build --all-features && \ cargo test --all-features && \ cargo +nightly doc --all-features && \ cargo fmt --all -- --check && \ -cargo clippy -- -D warnings && \ +cargo clippy --all-features -- -D warnings && \ cargo check && \ cargo check --no-default-features ``` ```bash # Additional checks -cargo clippy -- -D warnings -W clippy::nursery -A clippy::significant_drop_tightening -A clippy::significant_drop_in_scrutinee -# cargo clippy -- -D warnings -W clippy::unwrap_used -W clippy::expect_used +cargo clippy --all-features -- -D warnings -W clippy::nursery -A clippy::significant_drop_tightening -A clippy::significant_drop_in_scrutinee +# cargo clippy --all-features -- -D warnings -W clippy::unwrap_used -W clippy::expect_used ``` ## Performance diff --git a/CHANGELOG.md b/CHANGELOG.md index 24848520..cf80daaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Revise code coverage section in `BUILD.md` to use `cargo-llvm-cov` - Increased code coverage in some modules + - Add `--all-features` to clippy usage in `BUILD.md` and `ci.yml` + - Fixed various clippy warnings ### Fixed - Fixed chunk key encoding for 0 dimensional arrays with `default` and `v2` encoding diff --git a/src/array/array_async.rs b/src/array/array_async.rs index c8542cbe..30429d97 100644 --- a/src/array/array_async.rs +++ b/src/array/array_async.rs @@ -99,7 +99,7 @@ impl Array { /// - `chunk_indices` are invalid, /// - there is a codec decoding error, or /// - an underlying store error. - pub async fn async_retrieve_chunk_elements( + pub async fn async_retrieve_chunk_elements( &self, chunk_indices: &[u64], ) -> Result, ArrayError> { @@ -144,7 +144,9 @@ impl Array { /// /// # Panics /// Will panic if a chunk dimension is larger than `usize::MAX`. - pub async fn async_retrieve_chunk_ndarray( + pub async fn async_retrieve_chunk_ndarray< + T: safe_transmute::TriviallyTransmutable + Send + Sync, + >( &self, chunk_indices: &[u64], ) -> Result, ArrayError> { @@ -425,7 +427,7 @@ impl Array { self._async_retrieve_array_subset(array_subset, true).await } - async fn _async_retrieve_array_subset_elements( + async fn _async_retrieve_array_subset_elements( &self, array_subset: &ArraySubset, parallel: bool, @@ -469,7 +471,7 @@ impl Array { /// - an array subset is invalid or out of bounds of the array, /// - there is a codec decoding error, or /// - an underlying store error. - pub async fn async_retrieve_array_subset_elements( + pub async fn async_retrieve_array_subset_elements( &self, array_subset: &ArraySubset, ) -> Result, ArrayError> { @@ -479,7 +481,9 @@ impl Array { /// Parallel version of [`Array::retrieve_array_subset_elements`]. #[allow(clippy::missing_panics_doc, clippy::missing_errors_doc)] - pub async fn async_par_retrieve_array_subset_elements( + pub async fn async_par_retrieve_array_subset_elements< + T: TriviallyTransmutable + Send + Sync, + >( &self, array_subset: &ArraySubset, ) -> Result, ArrayError> { @@ -488,7 +492,9 @@ impl Array { } #[cfg(feature = "ndarray")] - async fn _async_retrieve_array_subset_ndarray( + async fn _async_retrieve_array_subset_ndarray< + T: safe_transmute::TriviallyTransmutable + Send + Sync, + >( &self, array_subset: &ArraySubset, parallel: bool, @@ -529,7 +535,9 @@ impl Array { /// /// # Panics /// Will panic if any dimension in `chunk_subset` is `usize::MAX` or larger. - pub async fn async_retrieve_array_subset_ndarray( + pub async fn async_retrieve_array_subset_ndarray< + T: safe_transmute::TriviallyTransmutable + Send + Sync, + >( &self, array_subset: &ArraySubset, ) -> Result, ArrayError> { @@ -541,7 +549,7 @@ impl Array { /// Parallel version of [`Array::retrieve_array_subset_ndarray`]. #[allow(clippy::missing_panics_doc, clippy::missing_errors_doc)] pub async fn async_par_retrieve_array_subset_ndarray< - T: safe_transmute::TriviallyTransmutable, + T: safe_transmute::TriviallyTransmutable + Send + Sync, >( &self, array_subset: &ArraySubset, @@ -610,7 +618,7 @@ impl Array { /// - the chunk subset is invalid, /// - there is a codec decoding error, or /// - an underlying store error. - pub async fn async_retrieve_chunk_subset_elements( + pub async fn async_retrieve_chunk_subset_elements( &self, chunk_indices: &[u64], chunk_subset: &ArraySubset, @@ -657,7 +665,7 @@ impl Array { /// /// # Panics /// Will panic if the number of elements in `chunk_subset` is `usize::MAX` or larger. - pub async fn async_retrieve_chunk_subset_ndarray( + pub async fn async_retrieve_chunk_subset_ndarray( &self, chunk_indices: &[u64], chunk_subset: &ArraySubset, @@ -803,7 +811,7 @@ impl Array { /// Returns an [`ArrayError`] if /// - the size of `T` does not match the data type size, or /// - a [`store_chunk`](Array::store_chunk) error condition is met. - pub async fn async_store_chunk_elements( + pub async fn async_store_chunk_elements( &self, chunk_indices: &[u64], chunk_elements: Vec, @@ -827,7 +835,9 @@ impl Array { /// - the size of `T` does not match the size of the data type, /// - a [`store_chunk_elements`](Array::store_chunk_elements) error condition is met. #[allow(clippy::missing_panics_doc)] - pub async fn async_store_chunk_ndarray( + pub async fn async_store_chunk_ndarray< + T: safe_transmute::TriviallyTransmutable + Send + Sync, + >( &self, chunk_indices: &[u64], chunk_array: &ndarray::ArrayViewD<'_, T>, @@ -1050,7 +1060,7 @@ impl .await } - async fn _async_store_array_subset_elements( + async fn _async_store_array_subset_elements( &self, array_subset: &ArraySubset, subset_elements: Vec, @@ -1076,7 +1086,7 @@ impl /// Returns an [`ArrayError`] if /// - the size of `T` does not match the data type size, or /// - a [`store_array_subset`](Array::store_array_subset) error condition is met. - pub async fn async_store_array_subset_elements( + pub async fn async_store_array_subset_elements( &self, array_subset: &ArraySubset, subset_elements: Vec, @@ -1087,7 +1097,7 @@ impl /// Parallel version of [`Array::store_array_subset_elements`]. #[allow(clippy::missing_panics_doc, clippy::missing_errors_doc)] - pub async fn async_par_store_array_subset_elements( + pub async fn async_par_store_array_subset_elements( &self, array_subset: &ArraySubset, subset_elements: Vec, @@ -1097,7 +1107,9 @@ impl } #[cfg(feature = "ndarray")] - async fn _async_store_array_subset_ndarray( + async fn _async_store_array_subset_ndarray< + T: safe_transmute::TriviallyTransmutable + Send + Sync, + >( &self, subset_start: &[u64], subset_array: &ndarray::ArrayViewD<'_, T>, @@ -1135,7 +1147,9 @@ impl /// # Errors /// Returns an [`ArrayError`] if a [`store_array_subset_elements`](Array::store_array_subset_elements) error condition is met. #[allow(clippy::missing_panics_doc)] - pub async fn async_store_array_subset_ndarray( + pub async fn async_store_array_subset_ndarray< + T: safe_transmute::TriviallyTransmutable + Send + Sync, + >( &self, subset_start: &[u64], subset_array: &ndarray::ArrayViewD<'_, T>, @@ -1147,7 +1161,9 @@ impl #[cfg(feature = "ndarray")] /// Parallel version of [`Array::store_array_subset_ndarray`]. #[allow(clippy::missing_panics_doc, clippy::missing_errors_doc)] - pub async fn async_par_store_array_subset_ndarray( + pub async fn async_par_store_array_subset_ndarray< + T: safe_transmute::TriviallyTransmutable + Send + Sync, + >( &self, subset_start: &[u64], subset_array: &ndarray::ArrayViewD<'_, T>, @@ -1240,7 +1256,7 @@ impl /// Returns an [`ArrayError`] if /// - the size of `T` does not match the data type size, or /// - a [`store_chunk_subset`](Array::store_chunk_subset) error condition is met. - pub async fn async_store_chunk_subset_elements( + pub async fn async_store_chunk_subset_elements( &self, chunk_indices: &[u64], chunk_subset: &ArraySubset, @@ -1266,7 +1282,7 @@ impl /// # Errors /// Returns an [`ArrayError`] if a [`store_chunk_subset_elements`](Array::store_chunk_subset_elements) error condition is met. #[allow(clippy::missing_panics_doc)] - pub async fn async_store_chunk_subset_ndarray( + pub async fn async_store_chunk_subset_ndarray( &self, chunk_indices: &[u64], chunk_subset_start: &[u64], diff --git a/src/array/chunk_key_encoding.rs b/src/array/chunk_key_encoding.rs index d885f098..70b4e773 100644 --- a/src/array/chunk_key_encoding.rs +++ b/src/array/chunk_key_encoding.rs @@ -53,7 +53,7 @@ where T: ChunkKeyEncodingTraits + 'static, { fn from(chunk_key_encoding: T) -> Self { - ChunkKeyEncoding::new(chunk_key_encoding) + Self::new(chunk_key_encoding) } } diff --git a/src/array/codec/array_to_array/bitround.rs b/src/array/codec/array_to_array/bitround.rs index 249e61c9..758b1302 100644 --- a/src/array/codec/array_to_array/bitround.rs +++ b/src/array/codec/array_to_array/bitround.rs @@ -44,46 +44,40 @@ fn create_codec_bitround(metadata: &Metadata) -> Result u16 { - if keepbits >= maxbits { - input - } else { +const fn round_bits16(mut input: u16, keepbits: u32, maxbits: u32) -> u16 { + if keepbits < maxbits { let maskbits = maxbits - keepbits; let all_set = u16::MAX; let mask = (all_set >> maskbits) << maskbits; let half_quantum1 = (1 << (maskbits - 1)) - 1; input += ((input >> maskbits) & 1) + half_quantum1; input &= mask; - input } + input } -fn round_bits32(mut input: u32, keepbits: u32, maxbits: u32) -> u32 { - if keepbits >= maxbits { - input - } else { +const fn round_bits32(mut input: u32, keepbits: u32, maxbits: u32) -> u32 { + if keepbits < maxbits { let maskbits = maxbits - keepbits; let all_set = u32::MAX; let mask = (all_set >> maskbits) << maskbits; let half_quantum1 = (1 << (maskbits - 1)) - 1; input += ((input >> maskbits) & 1) + half_quantum1; input &= mask; - input } + input } -fn round_bits64(mut input: u64, keepbits: u32, maxbits: u32) -> u64 { - if keepbits >= maxbits { - input - } else { +const fn round_bits64(mut input: u64, keepbits: u32, maxbits: u32) -> u64 { + if keepbits < maxbits { let maskbits = maxbits - keepbits; let all_set = u64::MAX; let mask = (all_set >> maskbits) << maskbits; let half_quantum1 = (1 << (maskbits - 1)) - 1; input += ((input >> maskbits) & 1) + half_quantum1; input &= mask; - input } + input } fn round_bytes(bytes: &mut [u8], data_type: &DataType, keepbits: u32) -> Result<(), CodecError> { diff --git a/src/array/codec/array_to_array/bitround/bitround_codec.rs b/src/array/codec/array_to_array/bitround/bitround_codec.rs index 4c34b3bb..22bbb639 100644 --- a/src/array/codec/array_to_array/bitround/bitround_codec.rs +++ b/src/array/codec/array_to_array/bitround/bitround_codec.rs @@ -22,13 +22,13 @@ impl BitroundCodec { /// /// `keepbits` is the number of bits to round to in the floating point mantissa. #[must_use] - pub fn new(keepbits: u32) -> Self { + pub const fn new(keepbits: u32) -> Self { Self { keepbits } } /// Create a new `bitround` codec from a configuration. #[must_use] - pub fn new_with_configuration(configuration: &BitroundCodecConfiguration) -> Self { + pub const fn new_with_configuration(configuration: &BitroundCodecConfiguration) -> Self { let BitroundCodecConfiguration::V1(configuration) = configuration; Self { keepbits: configuration.keepbits, diff --git a/src/array/codec/array_to_bytes/sharding/sharding_partial_decoder.rs b/src/array/codec/array_to_bytes/sharding/sharding_partial_decoder.rs index 8944cb12..aa66c36f 100644 --- a/src/array/codec/array_to_bytes/sharding/sharding_partial_decoder.rs +++ b/src/array/codec/array_to_bytes/sharding/sharding_partial_decoder.rs @@ -617,7 +617,7 @@ impl AsyncArrayPartialDecoderTraits for AsyncShardingPartialDecoder<'_> { &chunk_representation, ) .await?; - let overlap = unsafe { array_subset.overlap_unchecked(&chunk_subset) }; + let overlap = unsafe { array_subset.overlap_unchecked(chunk_subset) }; let array_subset_in_chunk_subset = unsafe { overlap.relative_to_unchecked(chunk_subset.start()) }; // Partial decoding is actually really slow with the blosc codec! Assume sharded chunks are small, and just decode the whole thing and extract bytes @@ -682,7 +682,7 @@ impl AsyncArrayPartialDecoderTraits for AsyncShardingPartialDecoder<'_> { // Write filled chunks filled_chunks.par_iter().for_each(|chunk_subset| { - let overlap = unsafe { array_subset.overlap_unchecked(&chunk_subset) }; + let overlap = unsafe { array_subset.overlap_unchecked(chunk_subset) }; let chunk_subset_in_array_subset = unsafe { overlap.relative_to_unchecked(array_subset.start()) }; let mut data_idx = 0; diff --git a/src/array/codec/array_to_bytes/zfp.rs b/src/array/codec/array_to_bytes/zfp.rs index d9311ab2..2777364b 100644 --- a/src/array/codec/array_to_bytes/zfp.rs +++ b/src/array/codec/array_to_bytes/zfp.rs @@ -73,7 +73,7 @@ pub struct ZfpExpertParams { pub minexp: i32, } -fn zarr_data_type_to_zfp_data_type(data_type: &DataType) -> Option { +const fn zarr_data_type_to_zfp_data_type(data_type: &DataType) -> Option { match data_type { DataType::Int32 | DataType::UInt32 => Some(zfp_type_zfp_type_int32), DataType::Int64 | DataType::UInt64 => Some(zfp_type_zfp_type_int64), diff --git a/src/array/codec/array_to_bytes/zfp/zfp_bitstream.rs b/src/array/codec/array_to_bytes/zfp/zfp_bitstream.rs index 51135a1a..0a3d1947 100644 --- a/src/array/codec/array_to_bytes/zfp/zfp_bitstream.rs +++ b/src/array/codec/array_to_bytes/zfp/zfp_bitstream.rs @@ -20,7 +20,7 @@ impl ZfpBitstream { NonNull::new(stream).map(Self) } - pub fn as_bitstream(&self) -> *mut bitstream { + pub const fn as_bitstream(&self) -> *mut bitstream { self.0.as_ptr() } } diff --git a/src/array/codec/array_to_bytes/zfp/zfp_codec.rs b/src/array/codec/array_to_bytes/zfp/zfp_codec.rs index 5609be83..ece196ca 100644 --- a/src/array/codec/array_to_bytes/zfp/zfp_codec.rs +++ b/src/array/codec/array_to_bytes/zfp/zfp_codec.rs @@ -55,7 +55,7 @@ pub struct ZfpCodec { impl ZfpCodec { /// Create a new `Zfp` codec in expert mode. #[must_use] - pub fn new_expert(expert_params: ZfpExpertParams) -> Self { + pub const fn new_expert(expert_params: ZfpExpertParams) -> Self { Self { mode: ZfpMode::Expert(expert_params), } @@ -63,7 +63,7 @@ impl ZfpCodec { /// Create a new `Zfp` codec in fixed rate mode. #[must_use] - pub fn new_fixed_rate(rate: f64) -> Self { + pub const fn new_fixed_rate(rate: f64) -> Self { Self { mode: ZfpMode::FixedRate(rate), } @@ -71,7 +71,7 @@ impl ZfpCodec { /// Create a new `Zfp` codec in fixed precision mode. #[must_use] - pub fn new_fixed_precision(precision: u32) -> Self { + pub const fn new_fixed_precision(precision: u32) -> Self { Self { mode: ZfpMode::FixedPrecision(precision), } @@ -79,7 +79,7 @@ impl ZfpCodec { /// Create a new `Zfp` codec in fixed accuracy mode. #[must_use] - pub fn new_fixed_accuracy(tolerance: f64) -> Self { + pub const fn new_fixed_accuracy(tolerance: f64) -> Self { Self { mode: ZfpMode::FixedAccuracy(tolerance), } @@ -87,7 +87,7 @@ impl ZfpCodec { /// Create a new `Zfp` codec in reversible mode. #[must_use] - pub fn new_reversible() -> Self { + pub const fn new_reversible() -> Self { Self { mode: ZfpMode::Reversible, } @@ -95,7 +95,7 @@ impl ZfpCodec { /// Create a new `Zfp` codec from configuration. #[must_use] - pub fn new_with_configuration(configuration: &ZfpCodecConfiguration) -> Self { + pub const fn new_with_configuration(configuration: &ZfpCodecConfiguration) -> Self { type V1 = ZfpCodecConfigurationV1; let ZfpCodecConfiguration::V1(configuration) = configuration; match configuration { @@ -227,7 +227,7 @@ impl ArrayToBytesCodecTraits for ZfpCodec { Ok(Box::new(zfp_partial_decoder::ZfpPartialDecoder::new( input_handle, decoded_representation, - self.mode.clone(), + self.mode, )?)) } @@ -240,7 +240,7 @@ impl ArrayToBytesCodecTraits for ZfpCodec { Ok(Box::new(zfp_partial_decoder::AsyncZfpPartialDecoder::new( input_handle, decoded_representation, - self.mode.clone(), + self.mode, )?)) } diff --git a/src/array/codec/array_to_bytes/zfp/zfp_configuration.rs b/src/array/codec/array_to_bytes/zfp/zfp_configuration.rs index 9dc47331..5dcaca2e 100644 --- a/src/array/codec/array_to_bytes/zfp/zfp_configuration.rs +++ b/src/array/codec/array_to_bytes/zfp/zfp_configuration.rs @@ -103,7 +103,7 @@ pub struct ZfpFixedRateConfiguration { } /// The `zfp` configuration for fixed precision mode. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Display)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Display)] pub struct ZfpFixedPrecisionConfiguration { /// The precision specifies how many uncompressed bits per value to store, and indirectly governs the relative error. pub precision: u32, diff --git a/src/array/codec/array_to_bytes/zfp/zfp_field.rs b/src/array/codec/array_to_bytes/zfp/zfp_field.rs index 9d5dca8d..36c92b39 100644 --- a/src/array/codec/array_to_bytes/zfp/zfp_field.rs +++ b/src/array/codec/array_to_bytes/zfp/zfp_field.rs @@ -18,7 +18,7 @@ impl Drop for ZfpField { } #[allow(non_upper_case_globals)] -fn zfp_type_to_size(zfp_type_: zfp_type) -> Option { +const fn zfp_type_to_size(zfp_type_: zfp_type) -> Option { match zfp_type_ { zfp_type_zfp_type_int32 | zfp_type_zfp_type_float => Some(4), zfp_type_zfp_type_int64 | zfp_type_zfp_type_double => Some(8), @@ -29,10 +29,10 @@ fn zfp_type_to_size(zfp_type_: zfp_type) -> Option { impl ZfpField { pub fn new(data: &mut [u8], zfp_type_: zfp_type, shape: &[usize]) -> Option { match shape.len() { - 1 => ZfpField::new_1d(data, zfp_type_, shape[0]), - 2 => ZfpField::new_2d(data, zfp_type_, shape[1], shape[0]), - 3 => ZfpField::new_3d(data, zfp_type_, shape[2], shape[1], shape[0]), - 4 => ZfpField::new_4d(data, zfp_type_, shape[3], shape[2], shape[1], shape[0]), + 1 => Self::new_1d(data, zfp_type_, shape[0]), + 2 => Self::new_2d(data, zfp_type_, shape[1], shape[0]), + 3 => Self::new_3d(data, zfp_type_, shape[2], shape[1], shape[0]), + 4 => Self::new_4d(data, zfp_type_, shape[3], shape[2], shape[1], shape[0]), _ => None, } } @@ -102,7 +102,7 @@ impl ZfpField { NonNull::new(field).map(Self) } - pub fn as_zfp_field(&self) -> *mut zfp_field { + pub const fn as_zfp_field(&self) -> *mut zfp_field { self.0.as_ptr() } } diff --git a/src/array/codec/array_to_bytes/zfp/zfp_partial_decoder.rs b/src/array/codec/array_to_bytes/zfp/zfp_partial_decoder.rs index f6fa134f..87e36b6d 100644 --- a/src/array/codec/array_to_bytes/zfp/zfp_partial_decoder.rs +++ b/src/array/codec/array_to_bytes/zfp/zfp_partial_decoder.rs @@ -29,17 +29,21 @@ impl<'a> ZfpPartialDecoder<'a> { decoded_representation: &ArrayRepresentation, mode: ZfpMode, ) -> Result { - match zarr_data_type_to_zfp_data_type(decoded_representation.data_type()) { - Some(zfp_type) => Ok(Self { - input_handle, - decoded_representation: decoded_representation.clone(), - mode, - zfp_type, - }), - None => Err(CodecError::from( - "data type {} is unsupported for zfp codec", - )), - } + zarr_data_type_to_zfp_data_type(decoded_representation.data_type()).map_or_else( + || { + Err(CodecError::from( + "data type {} is unsupported for zfp codec", + )) + }, + |zfp_type| { + Ok(Self { + input_handle, + decoded_representation: decoded_representation.clone(), + mode, + zfp_type, + }) + }, + ) } } @@ -101,17 +105,21 @@ impl<'a> AsyncZfpPartialDecoder<'a> { decoded_representation: &ArrayRepresentation, mode: ZfpMode, ) -> Result { - match zarr_data_type_to_zfp_data_type(decoded_representation.data_type()) { - Some(zfp_type) => Ok(Self { - input_handle, - decoded_representation: decoded_representation.clone(), - mode, - zfp_type, - }), - None => Err(CodecError::from( - "data type {} is unsupported for zfp codec", - )), - } + zarr_data_type_to_zfp_data_type(decoded_representation.data_type()).map_or_else( + || { + Err(CodecError::from( + "data type {} is unsupported for zfp codec", + )) + }, + |zfp_type| { + Ok(Self { + input_handle, + decoded_representation: decoded_representation.clone(), + mode, + zfp_type, + }) + }, + ) } } diff --git a/src/array/codec/array_to_bytes/zfp/zfp_stream.rs b/src/array/codec/array_to_bytes/zfp/zfp_stream.rs index 1a3b5a54..942fe0d8 100644 --- a/src/array/codec/array_to_bytes/zfp/zfp_stream.rs +++ b/src/array/codec/array_to_bytes/zfp/zfp_stream.rs @@ -54,7 +54,7 @@ impl ZfpStream { NonNull::new(zfp).map(Self) } - pub fn as_zfp_stream(&self) -> *mut zfp_stream { + pub const fn as_zfp_stream(&self) -> *mut zfp_stream { self.0.as_ptr() } } diff --git a/src/storage/store/store_async/amazon_s3_store.rs b/src/storage/store/store_async/amazon_s3_store.rs index c3db9685..5e9d7d26 100644 --- a/src/storage/store/store_async/amazon_s3_store.rs +++ b/src/storage/store/store_async/amazon_s3_store.rs @@ -10,6 +10,7 @@ pub struct AsyncAmazonS3Store { impl AsyncAmazonS3Store { /// Create a new amazon S3 store. + #[must_use] pub fn new(object_store: object_store::aws::AmazonS3) -> Self { Self { object_store } } diff --git a/src/storage/store/store_async/google_cloud_store.rs b/src/storage/store/store_async/google_cloud_store.rs index f5828950..09bdf9ce 100644 --- a/src/storage/store/store_async/google_cloud_store.rs +++ b/src/storage/store/store_async/google_cloud_store.rs @@ -10,6 +10,7 @@ pub struct AsyncGoogleCloudStore { impl AsyncGoogleCloudStore { /// Create a new amazon S3 store. + #[must_use] pub fn new(object_store: object_store::gcp::GoogleCloudStorage) -> Self { Self { object_store } } diff --git a/src/storage/store/store_async/microsoft_azure_store.rs b/src/storage/store/store_async/microsoft_azure_store.rs index 69d47739..b24d4642 100644 --- a/src/storage/store/store_async/microsoft_azure_store.rs +++ b/src/storage/store/store_async/microsoft_azure_store.rs @@ -10,6 +10,7 @@ pub struct AsyncMicrosoftAzureStore { impl AsyncMicrosoftAzureStore { /// Create a new amazon S3 store. + #[must_use] pub fn new(object_store: object_store::azure::MicrosoftAzure) -> Self { Self { object_store } } diff --git a/src/storage/store_key_lock.rs b/src/storage/store_key_lock.rs new file mode 100644 index 00000000..a6834c4a --- /dev/null +++ b/src/storage/store_key_lock.rs @@ -0,0 +1,14 @@ +use std::sync::Arc; + +use parking_lot::{RwLockReadGuard, RwLockWriteGuard}; + +/// Traits for a store key lock. +pub trait StoreKeyLockTraits { + /// Locks this [`StoreKeyLock`] with shared read access, blocking the current thread until it can be acquired. + fn read(&self) -> RwLockReadGuard<'_, ()>; + + /// Locks this [`StoreKeyLock`] with exclusive write access, blocking the current thread until it can be acquired. + fn write(&self) -> RwLockWriteGuard<'_, ()>; +} + +pub type StoreKeyLock = Arc;