teller_providers/
lib.rs

1pub mod config;
2pub mod providers;
3pub mod registry;
4
5use async_trait::async_trait;
6
7use crate::config::{PathMap, ProviderInfo, KV};
8
9#[async_trait]
10pub trait Provider {
11    fn kind(&self) -> ProviderInfo;
12    /// Get a mapping
13    ///
14    /// # Errors
15    ///
16    /// ...
17    async fn get(&self, pm: &PathMap) -> Result<Vec<KV>>;
18    /// Put a mapping
19    ///
20    /// # Errors
21    ///
22    /// ...
23    async fn put(&self, pm: &PathMap, kvs: &[KV]) -> Result<()>;
24    /// Delete a mapping
25    ///
26    /// # Errors
27    ///
28    /// ...
29    async fn del(&self, pm: &PathMap) -> Result<()>;
30}
31#[derive(thiserror::Error, Debug)]
32pub enum Error {
33    #[error("{0}")]
34    Message(String),
35
36    #[error("{0}: {1}")]
37    PathError(String, String),
38
39    #[error(transparent)]
40    IO(#[from] std::io::Error),
41
42    #[error(transparent)]
43    Env(#[from] std::env::VarError),
44
45    #[error(transparent)]
46    Any(#[from] Box<dyn std::error::Error + Send + Sync>),
47
48    #[error(transparent)]
49    Json(#[from] serde_json::Error),
50
51    #[error(transparent)]
52    YAML(#[from] serde_yaml::Error),
53
54    #[error("NOT FOUND {path}: {msg}")]
55    NotFound { path: String, msg: String },
56
57    #[error("GET {path}: {msg}")]
58    GetError { path: String, msg: String },
59
60    #[error("DEL {path}: {msg}")]
61    DeleteError { path: String, msg: String },
62
63    #[error("PUT {path}: {msg}")]
64    PutError { path: String, msg: String },
65
66    #[error("LIST {path}: {msg}")]
67    ListError { path: String, msg: String },
68
69    #[error("{0}")]
70    CreateProviderError(String),
71}
72
73pub type Result<T, E = Error> = std::result::Result<T, E>;