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
use async_trait::async_trait;
use std::{fmt::Display, sync::Arc};
mod prometheus {
include!(concat!(env!("OUT_DIR"), "/prometheus.rs"));
}
pub use prometheus::*;
#[derive(Debug)]
pub enum Error {
SnappyEncode(snap::Error),
SnappyDecode(snap::Error),
ProtoDecode(prost::DecodeError),
}
pub type Result<T> = std::result::Result<T, Error>;
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::SnappyEncode(_) => f.write_str("SnappyEncode"),
Self::SnappyDecode(_) => f.write_str("SnappyDecode"),
Self::ProtoDecode(_) => f.write_str("ProtoDecode"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::SnappyEncode(e) => Some(e),
Self::SnappyDecode(e) => Some(e),
Self::ProtoDecode(e) => Some(e),
}
}
}
#[async_trait]
pub trait RemoteStorage {
async fn write(&self, req: WriteRequest) -> Result<()>;
async fn read(&self, req: ReadRequest) -> Result<ReadResponse>;
}
pub type RemoteStorageRef = Arc<dyn RemoteStorage + Send + Sync>;