Skip to main content

rullst_orm/
repository.rs

1use async_trait::async_trait;
2
3#[async_trait]
4pub trait Repository<T>: Send + Sync {
5    type Id: Send + Sync;
6    type Error: Send + Sync;
7
8    async fn find_by_id(&self, id: Self::Id) -> Result<Option<T>, Self::Error>;
9    async fn find_all(&self) -> Result<Vec<T>, Self::Error>;
10    async fn save(&self, entity: &T) -> Result<(), Self::Error>;
11    async fn delete(&self, id: Self::Id) -> Result<(), Self::Error>;
12}
13
14pub struct GenericRepository<T> {
15    _marker: std::marker::PhantomData<T>,
16}
17
18impl<T> Default for GenericRepository<T> {
19    fn default() -> Self {
20        Self {
21            _marker: std::marker::PhantomData,
22        }
23    }
24}
25
26impl<T> GenericRepository<T> {
27    pub fn new() -> Self {
28        Self::default()
29    }
30}