pub trait Layer<A: Accessor> {
type LayeredAccessor: Accessor;
// Required method
fn layer(&self, inner: A) -> Self::LayeredAccessor;
}
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 async_trait::async_trait;
use opendal::raw::*;
use opendal::*;
/// Implement the real accessor logic here.
#[derive(Debug)]
struct TraceAccessor<A: Accessor> {
inner: A,
}
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
impl<A: Accessor> LayeredAccessor 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: Accessor> Layer<A> for TraceLayer {
type LayeredAccessor = TraceAccessor<A>;
fn layer(&self, inner: A) -> Self::LayeredAccessor {
TraceAccessor { inner }
}
}
Required Associated Types§
sourcetype LayeredAccessor: Accessor
type LayeredAccessor: Accessor
The layered accessor that returned by this layer.
Required Methods§
sourcefn layer(&self, inner: A) -> Self::LayeredAccessor
fn layer(&self, inner: A) -> Self::LayeredAccessor
Intercept the operations on the underlying storage.
Implementors§
source§impl<A: Accessor> Layer<A> for AsyncBacktraceLayer
Available on crate feature layers-async-backtrace
only.
impl<A: Accessor> Layer<A> for AsyncBacktraceLayer
Available on crate feature
layers-async-backtrace
only.type LayeredAccessor = AsyncBacktraceAccessor<A>
source§impl<A: Accessor> Layer<A> for AwaitTreeLayer
Available on crate feature layers-await-tree
only.
impl<A: Accessor> Layer<A> for AwaitTreeLayer
Available on crate feature
layers-await-tree
only.type LayeredAccessor = AwaitTreeAccessor<A>
source§impl<A: Accessor> Layer<A> for BlockingLayer
Available on crate feature layers-blocking
only.
impl<A: Accessor> Layer<A> for BlockingLayer
Available on crate feature
layers-blocking
only.type LayeredAccessor = BlockingAccessor<A>
source§impl<A: Accessor> Layer<A> for ChaosLayer
Available on crate feature layers-chaos
only.
impl<A: Accessor> Layer<A> for ChaosLayer
Available on crate feature
layers-chaos
only.type LayeredAccessor = ChaosAccessor<A>
source§impl<A: Accessor> Layer<A> for ConcurrentLimitLayer
impl<A: Accessor> Layer<A> for ConcurrentLimitLayer
type LayeredAccessor = ConcurrentLimitAccessor<A>
source§impl<A: Accessor> Layer<A> for DtraceLayer
Available on Linux and crate feature layers-dtrace
only.
impl<A: Accessor> Layer<A> for DtraceLayer
Available on Linux and crate feature
layers-dtrace
only.type LayeredAccessor = DTraceAccessor<A>
source§impl<A: Accessor> Layer<A> for ImmutableIndexLayer
impl<A: Accessor> Layer<A> for ImmutableIndexLayer
type LayeredAccessor = ImmutableIndexAccessor<A>
source§impl<A: Accessor> Layer<A> for LoggingLayer
impl<A: Accessor> Layer<A> for LoggingLayer
type LayeredAccessor = LoggingAccessor<A>
source§impl<A: Accessor> Layer<A> for MadsimLayer
Available on crate feature layers-madsim
only.
impl<A: Accessor> Layer<A> for MadsimLayer
Available on crate feature
layers-madsim
only.type LayeredAccessor = MadsimAccessor
source§impl<A: Accessor> Layer<A> for MetricsLayer
Available on crate feature layers-metrics
only.
impl<A: Accessor> Layer<A> for MetricsLayer
Available on crate feature
layers-metrics
only.type LayeredAccessor = MetricsAccessor<A>
source§impl<A: Accessor> Layer<A> for MinitraceLayer
Available on crate feature layers-minitrace
only.
impl<A: Accessor> Layer<A> for MinitraceLayer
Available on crate feature
layers-minitrace
only.type LayeredAccessor = MinitraceAccessor<A>
source§impl<A: Accessor> Layer<A> for OtelTraceLayer
Available on crate feature layers-otel-trace
only.
impl<A: Accessor> Layer<A> for OtelTraceLayer
Available on crate feature
layers-otel-trace
only.type LayeredAccessor = OtelTraceAccessor<A>
source§impl<A: Accessor> Layer<A> for PrometheusClientLayer
Available on crate feature layers-prometheus-client
only.
impl<A: Accessor> Layer<A> for PrometheusClientLayer
Available on crate feature
layers-prometheus-client
only.type LayeredAccessor = PrometheusAccessor<A>
source§impl<A: Accessor> Layer<A> for PrometheusLayer
Available on crate feature layers-prometheus
only.
impl<A: Accessor> Layer<A> for PrometheusLayer
Available on crate feature
layers-prometheus
only.type LayeredAccessor = PrometheusAccessor<A>
source§impl<A: Accessor> Layer<A> for ThrottleLayer
Available on crate feature layers-throttle
only.
impl<A: Accessor> Layer<A> for ThrottleLayer
Available on crate feature
layers-throttle
only.type LayeredAccessor = ThrottleAccessor<A>
source§impl<A: Accessor> Layer<A> for TimeoutLayer
impl<A: Accessor> Layer<A> for TimeoutLayer
type LayeredAccessor = TimeoutAccessor<A>
source§impl<A: Accessor> Layer<A> for TracingLayer
Available on crate feature layers-tracing
only.
impl<A: Accessor> Layer<A> for TracingLayer
Available on crate feature
layers-tracing
only.