1.5 KBRaw
| 1 | //! Repository ports. |
| 2 | //! |
| 3 | //! Traits only — the domain declares what persistence it needs, and |
| 4 | //! `infrastructure` supplies it. Every port has two implementations: an in-memory one |
| 5 | //! that makes use cases testable without a database, and a SQLite one for real use. |
| 6 | |
| 7 | pub mod membership_repo; |
| 8 | pub mod org_repo; |
| 9 | pub mod repo_repo; |
| 10 | pub mod session_repo; |
| 11 | pub mod token_repo; |
| 12 | pub mod user_repo; |
| 13 | |
| 14 | pub use membership_repo::MembershipRepository; |
| 15 | pub use org_repo::OrgRepository; |
| 16 | pub use repo_repo::RepoRepository; |
| 17 | pub use session_repo::SessionRepository; |
| 18 | pub use token_repo::TokenRepository; |
| 19 | pub use user_repo::UserRepository; |
| 20 | |
| 21 | /// What a repository can fail with. |
| 22 | /// |
| 23 | /// Storage failures are infrastructural and carry no domain meaning, so they collapse |
| 24 | /// into one opaque variant rather than leaking driver types upward. |
| 25 | #[derive(Debug)] |
| 26 | pub enum RepositoryError { |
| 27 | Backend(Box<dyn std::error::Error + Send + Sync>), |
| 28 | } |
| 29 | |
| 30 | impl RepositoryError { |
| 31 | pub fn backend(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self { |
| 32 | Self::Backend(error.into()) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | impl std::fmt::Display for RepositoryError { |
| 37 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 38 | match self { |
| 39 | Self::Backend(error) => write!(f, "storage failure: {error}"), |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | impl std::error::Error for RepositoryError { |
| 45 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 46 | match self { |
| 47 | Self::Backend(error) => Some(&**error), |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | pub type RepositoryResult<T> = Result<T, RepositoryError>; |