feat: user consent setting and retrieving (NOTE: does not affect recording yet)
This commit is contained in:
24
src/operator_ext.rs
Normal file
24
src/operator_ext.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use extension_traits::extension;
|
||||
use opendal::{Buffer, Error, ErrorKind, FuturesAsyncReader, Operator};
|
||||
|
||||
#[extension(pub trait OperatorExt)]
|
||||
impl Operator {
|
||||
async fn read_if_exists(&self, path: &str) -> Result<Option<Buffer>, Error> {
|
||||
match self.read(path).await {
|
||||
Ok(buffer) => Ok(Some(buffer)),
|
||||
Err(error) if matches!(error.kind(), ErrorKind::NotFound) => Ok(None),
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
}
|
||||
|
||||
async fn async_reader_if_exists(
|
||||
&self,
|
||||
path: &str,
|
||||
) -> Result<Option<FuturesAsyncReader>, Error> {
|
||||
match self.reader(path).await {
|
||||
Ok(reader) => Ok(Some(reader.into_futures_async_read(..).await?)),
|
||||
Err(error) if matches!(error.kind(), ErrorKind::NotFound) => Ok(None),
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user