1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//! Repository port traits for data access.
//!
//! These traits define the interface between the domain layer and the
//! persistence layer. Implementations live in adapter crates (e.g.
//! `aro-fletch`), keeping the core free of framework dependencies.
//!
//! All trait methods return [`BoxFuture`] so that the traits are object-safe
//! and can be used with `dyn Repository<T>` for dynamic dispatch (e.g.
//! via `Dep<dyn Repository<User>>`).
//!
//! # Example
//!
//! ```ignore
//! async fn get_user(
//! repo: &dyn Repository<User>,
//! id: u64,
//! ) -> Result<User, RepoError> {
//! repo.find_by_id(id).await
//! }
//! ```
use Future;
use Pin;
use crateEntity;
use crateRepoError;
use crate;
/// A boxed future that is `Send` and tied to the lifetime of `&self`.
///
/// Used as the return type for object-safe async trait methods.
pub type BoxFuture<'a, T> = ;
/// Core CRUD repository trait for a given entity type.
///
/// Provides the standard create, read, update, and delete operations.
/// Implementations should map persistence-layer errors to [`RepoError`].
///
/// This trait is object-safe, enabling dynamic dispatch via `dyn Repository<T>`.
/// Trait for repositories that support filtered and sorted queries.
///
/// The `Filter` associated type allows each implementation to define
/// its own query DSL or filter struct without leaking persistence
/// details into the domain layer.
///
/// **Note:** `Queryable` is *not* object-safe because it has an associated type
/// (`Filter`). Use a concrete type or a trait alias when dynamic dispatch is needed.
/// Trait for repositories that support paginated queries over all rows.
///
/// Paginates every entity of type `T` without applying a filter. For filtered
/// pagination, use [`Queryable::find_page_by`].
///
/// This trait is object-safe.
/// Trait for managing transactional boundaries across repository operations.
///
/// This allows services to coordinate multiple repository calls within
/// a single database transaction without coupling to a specific
/// persistence backend.
///
/// **Note:** `TransactionManager` is *not* object-safe because `transaction`
/// has generic type parameters. Use a concrete type or a trait alias when
/// dynamic dispatch is needed.
///
/// # Example
///
/// ```ignore
/// async fn transfer<TM: TransactionManager>(
/// tm: &TM,
/// amount: u64,
/// ) -> Result<(), RepoError> {
/// tm.transaction(|ctx| async move {
/// // Obtain transaction-scoped repositories from `ctx` (backend-specific).
/// let from_repo = ctx.from_account_repo();
/// let to_repo = ctx.to_account_repo();
/// let mut from = from_repo.find_by_id(1).await?;
/// let mut to = to_repo.find_by_id(2).await?;
/// from.balance -= amount;
/// to.balance += amount;
/// from_repo.update(from).await?;
/// to_repo.update(to).await?;
/// Ok(())
/// }).await
/// }
/// ```