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
use async_trait::async_trait;
use serde::Deserialize;
use crate::models::List;
pub mod file;
pub mod http;
pub mod manager;
#[derive(Debug, Deserialize)]
pub struct SourceList {
sources: Vec<String>,
}
impl SourceList {
pub fn new(sources: Vec<String>) -> Self {
Self { sources }
}
pub fn sources(&self) -> &[String] {
self.sources.as_ref()
}
}
#[async_trait]
pub trait Source {
type Error: std::error::Error;
///
/// try to fetch the lists from this source
///
async fn fetch(&self) -> Result<List, Self::Error>;
///
/// lifetime in seconds until this source's cache is invalidated
/// and has to be fetched again.
///
fn lifetime(&self) -> u64;
}