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 implementor’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::Accessor;
use opendal::Layer;
/// Implement the real accessor logic here.
#[derive(Debug)]
struct TraceAccessor {
inner: Arc<dyn Accessor>,
}
impl Accessor for TraceAccessor {}
/// The public struct that exposed to users.
///
/// Will be used like `op.layer(TraceLayer)`
struct TraceLayer;
impl Layer for TraceLayer {
fn layer(&self, inner: Arc<dyn Accessor>) -> Arc<dyn Accessor> {
Arc::new(TraceAccessor { inner })
}
}