| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | pub mod membership_repo; |
| 8 | pub mod org_repo; |
| 9 | pub mod session_repo; |
| 10 | pub mod user_repo; |
| 11 | |
| 12 | pub use membership_repo::MembershipRepository; |
| 13 | pub use org_repo::OrgRepository; |
| 14 | pub use session_repo::SessionRepository; |
| 15 | pub use user_repo::UserRepository; |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | #[derive(Debug)] |
| 22 | pub enum RepositoryError { |
| 23 | Backend(Box<dyn std::error::Error + Send + Sync>), |
| 24 | } |
| 25 | |
| 26 | impl RepositoryError { |
| 27 | pub fn backend(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self { |
| 28 | Self::Backend(error.into()) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | impl std::fmt::Display for RepositoryError { |
| 33 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 34 | match self { |
| 35 | Self::Backend(error) => write!(f, "storage failure: {error}"), |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | impl std::error::Error for RepositoryError { |
| 41 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 42 | match self { |
| 43 | Self::Backend(error) => Some(&**error), |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | pub type RepositoryResult<T> = Result<T, RepositoryError>; |