From 41998b24875bc2158a18692a404e29beef8998d3 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Tue, 16 Jan 2024 23:09:46 +0000 Subject: [PATCH] Use `impl Trait` syntax for args in the `Storage` trait instead of generic parameter --- casper-server/src/storage/backends/memory.rs | 25 +++++++++----------- casper-server/src/storage/backends/mod.rs | 25 +++++++++----------- casper-server/src/storage/mod.rs | 25 +++++++++----------- 3 files changed, 33 insertions(+), 42 deletions(-) diff --git a/casper-server/src/storage/backends/memory.rs b/casper-server/src/storage/backends/memory.rs index 4a15a44..730d625 100644 --- a/casper-server/src/storage/backends/memory.rs +++ b/casper-server/src/storage/backends/memory.rs @@ -162,13 +162,10 @@ impl Storage for MemoryBackend { self.get_responses([key]).await.remove(0) } - async fn get_responses( + async fn get_responses( &self, - keys: KI, - ) -> Vec>, Self::Error>> - where - KI: IntoIterator, - { + keys: impl IntoIterator, + ) -> Vec>, Self::Error>> { let mut memory = self.inner.lock().await; let mut responses = Vec::new(); for key in keys { @@ -193,10 +190,10 @@ impl Storage for MemoryBackend { self.delete_responses_multi([key]).await.remove(0) } - async fn delete_responses_multi(&self, keys: KI) -> Vec> - where - KI: IntoIterator, - { + async fn delete_responses_multi( + &self, + keys: impl IntoIterator, + ) -> Vec> { let mut memory = self.inner.lock().await; let mut results = Vec::new(); for key in keys { @@ -217,10 +214,10 @@ impl Storage for MemoryBackend { self.store_responses([item]).await.remove(0) } - async fn store_responses<'a, I>(&self, items: I) -> Vec> - where - I: IntoIterator>, - { + async fn store_responses( + &self, + items: impl IntoIterator>, + ) -> Vec> { let mut memory = self.inner.lock().await; let mut results = Vec::new(); for item in items { diff --git a/casper-server/src/storage/backends/mod.rs b/casper-server/src/storage/backends/mod.rs index 783d234..9ce7384 100644 --- a/casper-server/src/storage/backends/mod.rs +++ b/casper-server/src/storage/backends/mod.rs @@ -96,13 +96,10 @@ impl Storage for Backend { } #[inline] - async fn get_responses( + async fn get_responses( &self, - keys: KI, - ) -> Vec>, Self::Error>> - where - KI: IntoIterator, - { + keys: impl IntoIterator, + ) -> Vec>, Self::Error>> { match self { Backend::Memory(inner) => inner.get_responses(keys).await, Backend::Redis(inner) => inner.get_responses(keys).await, @@ -110,10 +107,10 @@ impl Storage for Backend { } #[inline] - async fn delete_responses_multi(&self, keys: KI) -> Vec> - where - KI: IntoIterator, - { + async fn delete_responses_multi( + &self, + keys: impl IntoIterator, + ) -> Vec> { match self { Backend::Memory(inner) => inner.delete_responses_multi(keys).await, Backend::Redis(inner) => inner.delete_responses_multi(keys).await, @@ -121,10 +118,10 @@ impl Storage for Backend { } #[inline] - async fn store_responses<'a, I>(&self, items: I) -> Vec> - where - I: IntoIterator>, - { + async fn store_responses( + &self, + items: impl IntoIterator>, + ) -> Vec> { match self { Backend::Memory(inner) => inner.store_responses(items).await, Backend::Redis(inner) => inner.store_responses(items).await, diff --git a/casper-server/src/storage/mod.rs b/casper-server/src/storage/mod.rs index 59a2246..29f90f9 100644 --- a/casper-server/src/storage/mod.rs +++ b/casper-server/src/storage/mod.rs @@ -97,13 +97,10 @@ pub trait Storage { // Provided implementation // - async fn get_responses( + async fn get_responses( &self, - keys: KI, - ) -> Vec>, Self::Error>> - where - KI: IntoIterator, - { + keys: impl IntoIterator, + ) -> Vec>, Self::Error>> { // Create list of pending futures to poll them in parallel stream::iter(keys.into_iter().map(|key| self.get_response(key))) .buffered(Self::MAX_CONCURRENCY) @@ -111,10 +108,10 @@ pub trait Storage { .await } - async fn delete_responses_multi(&self, keys: KI) -> Vec> - where - KI: IntoIterator, - { + async fn delete_responses_multi( + &self, + keys: impl IntoIterator, + ) -> Vec> { // Create list of pending futures to poll them in parallel stream::iter(keys.into_iter().map(|key| self.delete_responses(key))) .buffered(Self::MAX_CONCURRENCY) @@ -122,10 +119,10 @@ pub trait Storage { .await } - async fn store_responses<'a, I>(&self, items: I) -> Vec> - where - I: IntoIterator>, - { + async fn store_responses( + &self, + items: impl IntoIterator>, + ) -> Vec> { // Create list of pending futures to poll them in parallel stream::iter(items.into_iter().map(|it| self.store_response(it))) .buffered(Self::MAX_CONCURRENCY)