use await_tree::InstrumentAwait;
use crate::raw::*;
use crate::*;
#[derive(Clone, Default)]
pub struct AwaitTreeLayer {}
impl AwaitTreeLayer {
pub fn new() -> Self {
Self {}
}
}
impl<A: Access> Layer<A> for AwaitTreeLayer {
type LayeredAccess = AwaitTreeAccessor<A>;
fn layer(&self, accessor: A) -> Self::LayeredAccess {
AwaitTreeAccessor { inner: accessor }
}
}
#[derive(Debug, Clone)]
pub struct AwaitTreeAccessor<A: Access> {
inner: A,
}
impl<A: Access> LayeredAccess for AwaitTreeAccessor<A> {
type Inner = A;
type Reader = A::Reader;
type BlockingReader = A::BlockingReader;
type Writer = A::Writer;
type BlockingWriter = A::BlockingWriter;
type Lister = A::Lister;
type BlockingLister = A::BlockingLister;
fn inner(&self) -> &Self::Inner {
&self.inner
}
async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> {
self.inner
.read(path, args)
.instrument_await(format!("opendal::{}", Operation::Read))
.await
}
async fn write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::Writer)> {
self.inner
.write(path, args)
.instrument_await(format!("opendal::{}", Operation::Write))
.await
}
async fn copy(&self, from: &str, to: &str, args: OpCopy) -> Result<RpCopy> {
self.inner()
.copy(from, to, args)
.instrument_await(format!("opendal::{}", Operation::Copy))
.await
}
async fn rename(&self, from: &str, to: &str, args: OpRename) -> Result<RpRename> {
self.inner()
.rename(from, to, args)
.instrument_await(format!("opendal::{}", Operation::Rename))
.await
}
async fn stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
self.inner
.stat(path, args)
.instrument_await(format!("opendal::{}", Operation::Stat))
.await
}
async fn delete(&self, path: &str, args: OpDelete) -> Result<RpDelete> {
self.inner
.delete(path, args)
.instrument_await(format!("opendal::{}", Operation::Delete))
.await
}
async fn list(&self, path: &str, args: OpList) -> Result<(RpList, Self::Lister)> {
self.inner
.list(path, args)
.instrument_await(format!("opendal::{}", Operation::List))
.await
}
async fn presign(&self, path: &str, args: OpPresign) -> Result<RpPresign> {
self.inner
.presign(path, args)
.instrument_await(format!("opendal::{}", Operation::Presign))
.await
}
async fn batch(&self, args: OpBatch) -> Result<RpBatch> {
self.inner
.batch(args)
.instrument_await(format!("opendal::{}", Operation::Batch))
.await
}
fn blocking_read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::BlockingReader)> {
self.inner.blocking_read(path, args)
}
fn blocking_write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::BlockingWriter)> {
self.inner.blocking_write(path, args)
}
fn blocking_list(&self, path: &str, args: OpList) -> Result<(RpList, Self::BlockingLister)> {
self.inner.blocking_list(path, args)
}
}