diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b3e6d2e..565a4eac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ ### Changed - Change `get_or_try_insert_with` to return a concrete error type rather - than a trait object. ([#23][gh-pull-0023]) + than a trait object. ([#23][gh-pull-0023], [#37][gh-pull-0037]) ## Version 0.5.2 @@ -112,6 +112,7 @@ [caffeine-git]: https://github.com/ben-manes/caffeine +[gh-pull-0037]: https://github.com/moka-rs/moka/pull/37/ [gh-pull-0033]: https://github.com/moka-rs/moka/pull/33/ [gh-issue-0031]: https://github.com/moka-rs/moka/issues/31/ [gh-pull-0030]: https://github.com/moka-rs/moka/pull/30/ diff --git a/src/future/cache.rs b/src/future/cache.rs index a35e82c7..5772a3d9 100644 --- a/src/future/cache.rs +++ b/src/future/cache.rs @@ -16,7 +16,6 @@ use std::{ any::TypeId, borrow::Borrow, collections::hash_map::RandomState, - error::Error, future::Future, hash::{BuildHasher, Hash}, sync::Arc, @@ -439,7 +438,7 @@ where pub async fn get_or_try_insert_with(&self, key: K, init: F) -> Result> where F: Future> + Send + 'static, - E: Error + Send + Sync + 'static, + E: Send + Sync + 'static, { let hash = self.base.hash(&key); let key = Arc::new(key); @@ -632,7 +631,7 @@ where ) -> Result> where F: Future>, - E: Error + Send + Sync + 'static, + E: Send + Sync + 'static, { if let Some(v) = self.base.get_with_hash(&key, hash) { return Ok(v); @@ -1166,8 +1165,9 @@ mod tests { async fn get_or_try_insert_with() { use std::sync::Arc; - #[derive(thiserror::Error, Debug)] - #[error("{}", _0)] + // Note that MyError does not implement std::error::Error trait + // like anyhow::Error. + #[derive(Debug)] pub struct MyError(String); type MyResult = Result>; diff --git a/src/future/value_initializer.rs b/src/future/value_initializer.rs index 419a7004..9a67f520 100644 --- a/src/future/value_initializer.rs +++ b/src/future/value_initializer.rs @@ -1,7 +1,6 @@ use async_lock::RwLock; use std::{ any::{Any, TypeId}, - error::Error, future::Future, hash::{BuildHasher, Hash}, sync::Arc, @@ -68,7 +67,7 @@ where pub(crate) async fn try_init_or_read(&self, key: Arc, init: F) -> InitResult where F: Future>, - E: Error + Send + Sync + 'static, + E: Send + Sync + 'static, { use InitResult::*; diff --git a/src/sync/cache.rs b/src/sync/cache.rs index ee8a3f37..2ccabef4 100644 --- a/src/sync/cache.rs +++ b/src/sync/cache.rs @@ -11,7 +11,6 @@ use std::{ any::TypeId, borrow::Borrow, collections::hash_map::RandomState, - error::Error, hash::{BuildHasher, Hash}, sync::Arc, time::Duration, @@ -423,7 +422,7 @@ where pub fn get_or_try_insert_with(&self, key: K, init: F) -> Result> where F: FnOnce() -> Result, - E: Error + Send + Sync + 'static, + E: Send + Sync + 'static, { let hash = self.base.hash(&key); let key = Arc::new(key); @@ -438,7 +437,7 @@ where ) -> Result> where F: FnOnce() -> Result, - E: Error + Send + Sync + 'static, + E: Send + Sync + 'static, { if let Some(v) = self.get_with_hash(&key, hash) { return Ok(v); @@ -1009,8 +1008,9 @@ mod tests { thread::{sleep, spawn}, }; - #[derive(thiserror::Error, Debug)] - #[error("{}", _0)] + // Note that MyError does not implement std::error::Error trait + // like anyhow::Error. + #[derive(Debug)] pub struct MyError(String); type MyResult = Result>; diff --git a/src/sync/value_initializer.rs b/src/sync/value_initializer.rs index 1a2d312a..8b6aecc2 100644 --- a/src/sync/value_initializer.rs +++ b/src/sync/value_initializer.rs @@ -1,7 +1,6 @@ use parking_lot::RwLock; use std::{ any::{Any, TypeId}, - error::Error, hash::{BuildHasher, Hash}, sync::Arc, }; @@ -63,7 +62,7 @@ where pub(crate) fn try_init_or_read(&self, key: Arc, init: F) -> InitResult where F: FnOnce() -> Result, - E: Error + Send + Sync + 'static, + E: Send + Sync + 'static, { use InitResult::*;