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
use {
crate::{
models::{
blog::Post,
core::{Comment, Part, User},
story::{Chapter, Character, Origin, Pairing, Series, Story, Tag, Warning},
wiki::{Category, Page},
Existing, Id, New,
},
uri::Uri,
},
std::error::Error,
};
#[cfg(feature = "with-backend")]
#[async_trait::async_trait]
pub trait BackendFactory {
type Error: Error;
type Backend: Backend<Self::Error>;
async fn create(&self, config: Uri) -> Result<Self::Backend, Self::Error>;
}
#[cfg(feature = "with-backend")]
#[rustfmt::skip]
#[async_trait::async_trait]
pub trait Backend<Err>:
BackendEntry<User, Err>
+ BackendEntry<Comment, Err>
+ BackendEntry<Part, Err>
+ BackendEntry<Post, Err>
+ BackendEntry<Chapter, Err>
+ BackendEntry<Origin, Err>
+ BackendEntry<Warning, Err>
+ BackendEntry<Pairing, Err>
+ BackendEntry<Character, Err>
+ BackendEntry<Tag, Err>
+ BackendEntry<Story, Err>
+ BackendEntry<Series, Err>
+ BackendEntry<Category, Err>
+ BackendEntry<Page, Err>
where
Err: Error,
{
async fn migrate(&self) -> Result<(), Err>;
}
#[cfg(feature = "with-backend")]
#[async_trait::async_trait]
pub trait BackendEntry<Entry, Error> {
async fn get(&self, id: Id) -> Result<Existing<Entry>, Error>;
async fn all(&self, cursor: Id, limit: usize) -> Result<Vec<Existing<Entry>>, Error>;
async fn create(&self, data: New<Entry>) -> Result<Id, Error>;
async fn update(&self, data: Existing<Entry>) -> Result<(), Error>;
async fn remove(&self, id: Id) -> Result<(), Error>;
}