use async_trait::async_trait; use std::clone::Clone; use std::fmt::Debug; use std::hash::Hash; use std::io::{Error, ErrorKind}; pub mod repository; pub mod user; #[async_trait] pub trait TryOptionLoad: Clone where K: Eq + Hash + Clone + Debug + Send + Sync, V: Clone + Debug + Send, { async fn try_option_load(&self, key: K) -> Result, Error>; } #[async_trait] impl TryOptionLoad for dataloader::non_cached::Loader where K: Eq + Hash + Clone + Debug + Send + Sync, V: Clone + Debug + Send, F: dataloader::BatchFn + Send + Sync, { async fn try_option_load(&self, key: K) -> Result, Error> { async fn internal_try_option_load( loader: &dataloader::non_cached::Loader, key: K, ) -> Result, Error> where K: Eq + Hash + Clone + Debug + Send + Sync, V: Clone + Debug + Send, F: dataloader::BatchFn + Send + Sync, { match loader.try_load(key).await { Ok(x) => Ok(Some(x)), Err(e) => match e.kind() { ErrorKind::NotFound => Ok(None), _ => Err(e), }, } } internal_try_option_load(self, key).await } } #[async_trait] impl TryOptionLoad for dataloader::cached::Loader where K: Eq + Hash + Clone + Debug + Send + Sync, V: Clone + Debug + Send, F: dataloader::BatchFn + Send + Sync, { async fn try_option_load(&self, key: K) -> Result, Error> { async fn internal_try_option_load( loader: &dataloader::cached::Loader, key: K, ) -> Result, Error> where K: Eq + Hash + Clone + Debug + Send + Sync, V: Clone + Debug + Send, F: dataloader::BatchFn + Send + Sync, { match loader.try_load(key).await { Ok(x) => Ok(Some(x)), Err(e) => match e.kind() { ErrorKind::NotFound => Ok(None), _ => Err(e), }, } } internal_try_option_load(self, key).await } }