#![cfg_attr(docsrs, feature(doc_cfg))]
#![deny(missing_docs)]
use opendal_core::raw::*;
use opendal_core::*;
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct AsyncBacktraceLayer {}
impl AsyncBacktraceLayer {
pub fn new() -> Self {
Self::default()
}
}
impl<A: Access> Layer<A> for AsyncBacktraceLayer {
type LayeredAccess = AsyncBacktraceAccessor<A>;
fn layer(&self, inner: A) -> Self::LayeredAccess {
AsyncBacktraceAccessor { inner }
}
}
#[doc(hidden)]
#[derive(Debug)]
pub struct AsyncBacktraceAccessor<A: Access> {
inner: A,
}
impl<A: Access> LayeredAccess for AsyncBacktraceAccessor<A> {
type Inner = A;
type Reader = AsyncBacktraceWrapper<A::Reader>;
type Writer = AsyncBacktraceWrapper<A::Writer>;
type Lister = AsyncBacktraceWrapper<A::Lister>;
type Deleter = AsyncBacktraceWrapper<A::Deleter>;
type Copier = A::Copier;
fn inner(&self) -> &Self::Inner {
&self.inner
}
#[async_backtrace::framed]
async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> {
self.inner
.read(path, args)
.await
.map(|(rp, r)| (rp, AsyncBacktraceWrapper::new(r)))
}
#[async_backtrace::framed]
async fn write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::Writer)> {
self.inner
.write(path, args)
.await
.map(|(rp, r)| (rp, AsyncBacktraceWrapper::new(r)))
}
#[async_backtrace::framed]
async fn copy(
&self,
from: &str,
to: &str,
args: OpCopy,
opts: OpCopier,
) -> Result<(RpCopy, Self::Copier)> {
self.inner.copy(from, to, args, opts.clone()).await
}
#[async_backtrace::framed]
async fn rename(&self, from: &str, to: &str, args: OpRename) -> Result<RpRename> {
self.inner.rename(from, to, args).await
}
#[async_backtrace::framed]
async fn stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
self.inner.stat(path, args).await
}
#[async_backtrace::framed]
async fn delete(&self) -> Result<(RpDelete, Self::Deleter)> {
self.inner
.delete()
.await
.map(|(rp, r)| (rp, AsyncBacktraceWrapper::new(r)))
}
#[async_backtrace::framed]
async fn list(&self, path: &str, args: OpList) -> Result<(RpList, Self::Lister)> {
self.inner
.list(path, args)
.await
.map(|(rp, r)| (rp, AsyncBacktraceWrapper::new(r)))
}
#[async_backtrace::framed]
async fn presign(&self, path: &str, args: OpPresign) -> Result<RpPresign> {
self.inner.presign(path, args).await
}
}
#[doc(hidden)]
pub struct AsyncBacktraceWrapper<R> {
inner: R,
}
impl<R> AsyncBacktraceWrapper<R> {
fn new(inner: R) -> Self {
Self { inner }
}
}
impl<R: oio::Read> oio::Read for AsyncBacktraceWrapper<R> {
#[async_backtrace::framed]
async fn read(&mut self) -> Result<Buffer> {
self.inner.read().await
}
}
impl<R: oio::Write> oio::Write for AsyncBacktraceWrapper<R> {
#[async_backtrace::framed]
async fn write(&mut self, bs: Buffer) -> Result<()> {
self.inner.write(bs).await
}
#[async_backtrace::framed]
async fn close(&mut self) -> Result<Metadata> {
self.inner.close().await
}
#[async_backtrace::framed]
async fn abort(&mut self) -> Result<()> {
self.inner.abort().await
}
}
impl<R: oio::List> oio::List for AsyncBacktraceWrapper<R> {
#[async_backtrace::framed]
async fn next(&mut self) -> Result<Option<oio::Entry>> {
self.inner.next().await
}
}
impl<R: oio::Delete> oio::Delete for AsyncBacktraceWrapper<R> {
#[async_backtrace::framed]
async fn delete(&mut self, path: &str, args: OpDelete) -> Result<()> {
self.inner.delete(path, args).await
}
#[async_backtrace::framed]
async fn close(&mut self) -> Result<()> {
self.inner.close().await
}
}