use async_trait::async_trait; use deadpool_diesel::Status; use derive_more::From; use diesel_async::AsyncPgConnection; use diesel_async::pooled_connection::deadpool::{Object, PoolError}; use lib::diesel::pool::PgPool; #[async_trait] pub trait GetConnection: Clone + Send + Sync { async fn get(&self) -> Result, GetConnectionError>; fn status(&self) -> Status; } #[async_trait] impl GetConnection for PgPool { async fn get(&self) -> Result, GetConnectionError> { self.get().await.map_err(Into::into) } #[inline] fn status(&self) -> Status { self.status() } } #[derive(Debug, From)] pub enum GetConnectionError { PoolError(PoolError), DieselError(diesel::result::Error), }