Skip to main content

aos/
lib.rs

1use std::error;
2use std::fmt;
3use std::path::Path;
4
5use tokio::io;
6
7use async_trait::async_trait;
8
9mod fs;
10
11#[derive(Debug)]
12enum Error {
13    Io(io::Error),
14}
15
16impl fmt::Display for Error {
17    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18        match *self {
19            Error::Io(ref err) => write!(f, "IO: {}", err),
20        }
21    }
22}
23
24impl error::Error for Error {
25    fn cause(&self) -> Option<&dyn error::Error> {
26        match *self {
27            Error::Io(ref err) => Some(err),
28        }
29    }
30}
31
32impl From<std::io::Error> for Error {
33    fn from(err: io::Error) -> Error {
34        Error::Io(err)
35    }
36}
37
38type Result<T> = std::result::Result<T, Error>;
39
40#[async_trait]
41trait Storager {
42    async fn stat(&self, path: &Path);
43    async fn delete(&self, path: &Path) -> Result<()>;
44    async fn read(&self, path: &Path) -> Result<Box<dyn tokio::io::AsyncRead + Unpin>>;
45    async fn write<R: io::AsyncRead + Unpin + Send + Sync>(
46        &self,
47        path: &Path,
48        r: &mut R,
49    ) -> Result<()>;
50}