Skip to main content

larust_orm/
repository.rs

1use std::marker::PhantomData;
2
3/// Stateless marker type `#[derive(Model)]` implements
4/// `larust_repository::Repository<T>` for - see `larust-macros`' `model.rs`
5/// for the actual generated `impl Repository<T> for AnyRepository<T>` body,
6/// which just forwards to the already-generated `T::find`/`create`/`update`/
7/// `delete` static methods and `QueryBuilder<T>`.
8///
9/// This can't be a single blanket `impl<T: FromRow<AnyRow>> Repository<T>
10/// for AnyRepository<T>` written once here in `larust-orm`, because
11/// `create`/`update` need to build INSERT/UPDATE SQL text from a specific
12/// struct's column names - information only available at macro-expansion
13/// time (`#[derive(Model)]` sees the real field list; a function generic
14/// over `T` here never does). So the impl is generated per-model instead,
15/// and this type stays a plain, zero-sized marker with no logic of its own.
16pub struct AnyRepository<T> {
17    _marker: PhantomData<fn() -> T>,
18}
19
20impl<T> AnyRepository<T> {
21    pub fn new() -> Self {
22        Self {
23            _marker: PhantomData,
24        }
25    }
26}
27
28impl<T> Default for AnyRepository<T> {
29    fn default() -> Self {
30        Self::new()
31    }
32}