pub trait Layer<A: Access> {
type LayeredAccess: Access;
// Required method
fn layer(&self, inner: A) -> Self::LayeredAccess;
}
Expand description
Layer is used to intercept the operations on the underlying storage.
Struct that implement this trait must accept input Arc<dyn Accessor>
as inner,
and returns a new Arc<dyn Accessor>
as output.
All functions in Accessor
requires &self
, so it’s implementer’s responsibility
to maintain the internal mutability. Please also keep in mind that Accessor
requires Send
and Sync
.
§Notes
§Inner
It’s required to implement fn inner() -> Option<Arc<dyn Accessor>>
for layer’s accessors.
By implement this method, all API calls will be forwarded to inner accessor instead.
§Examples
use std::sync::Arc;
use opendal::raw::*;
use opendal::*;
/// Implement the real accessor logic here.
#[derive(Debug)]
struct TraceAccessor<A: Access> {
inner: A,
}
impl<A: Access> LayeredAccess for TraceAccessor<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).await
}
fn blocking_read(
&self,
path: &str,
args: OpRead,
) -> Result<(RpRead, Self::BlockingReader)> {
self.inner.blocking_read(path, args)
}
async fn write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::Writer)> {
self.inner.write(path, args).await
}
fn blocking_write(
&self,
path: &str,
args: OpWrite,
) -> Result<(RpWrite, Self::BlockingWriter)> {
self.inner.blocking_write(path, args)
}
async fn list(&self, path: &str, args: OpList) -> Result<(RpList, Self::Lister)> {
self.inner.list(path, args).await
}
fn blocking_list(
&self,
path: &str,
args: OpList,
) -> Result<(RpList, Self::BlockingLister)> {
self.inner.blocking_list(path, args)
}
}
/// The public struct that exposed to users.
///
/// Will be used like `op.layer(TraceLayer)`
struct TraceLayer;
impl<A: Access> Layer<A> for TraceLayer {
type LayeredAccess = TraceAccessor<A>;
fn layer(&self, inner: A) -> Self::LayeredAccess {
TraceAccessor { inner }
}
}
Required Associated Types§
sourcetype LayeredAccess: Access
type LayeredAccess: Access
The layered accessor that returned by this layer.
Required Methods§
sourcefn layer(&self, inner: A) -> Self::LayeredAccess
fn layer(&self, inner: A) -> Self::LayeredAccess
Intercept the operations on the underlying storage.
Implementors§
source§impl<A: Access> Layer<A> for AsyncBacktraceLayer
Available on crate feature layers-async-backtrace
only.
impl<A: Access> Layer<A> for AsyncBacktraceLayer
Available on crate feature
layers-async-backtrace
only.type LayeredAccess = AsyncBacktraceAccessor<A>
source§impl<A: Access> Layer<A> for AwaitTreeLayer
Available on crate feature layers-await-tree
only.
impl<A: Access> Layer<A> for AwaitTreeLayer
Available on crate feature
layers-await-tree
only.type LayeredAccess = AwaitTreeAccessor<A>
source§impl<A: Access> Layer<A> for BlockingLayer
Available on crate feature layers-blocking
only.
impl<A: Access> Layer<A> for BlockingLayer
Available on crate feature
layers-blocking
only.type LayeredAccess = BlockingAccessor<A>
source§impl<A: Access> Layer<A> for ChaosLayer
Available on crate feature layers-chaos
only.
impl<A: Access> Layer<A> for ChaosLayer
Available on crate feature
layers-chaos
only.type LayeredAccess = ChaosAccessor<A>
source§impl<A: Access> Layer<A> for ConcurrentLimitLayer
impl<A: Access> Layer<A> for ConcurrentLimitLayer
type LayeredAccess = ConcurrentLimitAccessor<A>
source§impl<A: Access> Layer<A> for DtraceLayer
Available on Linux and crate feature layers-dtrace
only.
impl<A: Access> Layer<A> for DtraceLayer
Available on Linux and crate feature
layers-dtrace
only.type LayeredAccess = DTraceAccessor<A>
source§impl<A: Access> Layer<A> for FastraceLayer
Available on crate feature layers-fastrace
only.
impl<A: Access> Layer<A> for FastraceLayer
Available on crate feature
layers-fastrace
only.type LayeredAccess = FastraceAccessor<A>
source§impl<A: Access> Layer<A> for ImmutableIndexLayer
impl<A: Access> Layer<A> for ImmutableIndexLayer
type LayeredAccess = ImmutableIndexAccessor<A>
source§impl<A: Access> Layer<A> for opendal::layers::MetricsLayer
Available on crate feature layers-metrics
only.
impl<A: Access> Layer<A> for opendal::layers::MetricsLayer
Available on crate feature
layers-metrics
only.type LayeredAccess = MetricsAccessor<A, MetricsInterceptor>
source§impl<A: Access> Layer<A> for MimeGuessLayer
Available on crate feature layers-mime-guess
only.
impl<A: Access> Layer<A> for MimeGuessLayer
Available on crate feature
layers-mime-guess
only.type LayeredAccess = MimeGuessAccessor<A>
source§impl<A: Access> Layer<A> for OtelTraceLayer
Available on crate feature layers-otel-trace
only.
impl<A: Access> Layer<A> for OtelTraceLayer
Available on crate feature
layers-otel-trace
only.type LayeredAccess = OtelTraceAccessor<A>
source§impl<A: Access> Layer<A> for PrometheusClientLayer
Available on crate feature layers-prometheus-client
only.
impl<A: Access> Layer<A> for PrometheusClientLayer
Available on crate feature
layers-prometheus-client
only.type LayeredAccess = MetricsAccessor<A, PrometheusClientInterceptor>
source§impl<A: Access> Layer<A> for PrometheusLayer
Available on crate feature layers-prometheus
only.
impl<A: Access> Layer<A> for PrometheusLayer
Available on crate feature
layers-prometheus
only.type LayeredAccess = MetricsAccessor<A, PrometheusInterceptor>
source§impl<A: Access> Layer<A> for ThrottleLayer
Available on crate feature layers-throttle
only.
impl<A: Access> Layer<A> for ThrottleLayer
Available on crate feature
layers-throttle
only.type LayeredAccess = ThrottleAccessor<A>
source§impl<A: Access> Layer<A> for TimeoutLayer
impl<A: Access> Layer<A> for TimeoutLayer
type LayeredAccess = TimeoutAccessor<A>
source§impl<A: Access> Layer<A> for TracingLayer
Available on crate feature layers-tracing
only.
impl<A: Access> Layer<A> for TracingLayer
Available on crate feature
layers-tracing
only.