pub trait Layer {
    fn layer(&self, inner: Arc<dyn Accessor>) -> Arc<dyn Accessor>;
}
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.

Examples

use std::sync::Arc;

use opendal::Accessor;
use opendal::Layer;

#[derive(Debug)]
struct Trace {
    inner: Arc<dyn Accessor>,
}

impl Accessor for Trace {}

impl Layer for Trace {
    fn layer(&self, inner: Arc<dyn Accessor>) -> Arc<dyn Accessor> {
        Arc::new(Trace { inner })
    }
}

Required methods

Intercept the operations on the underlying storage.

Implementors

Implement Layer for backon::Backoff so that all backoff can be used as a layer

Example

use backon::ExponentialBackoff;
use opendal::Operator;

let op = Operator::new(accessor).layer(ExponentialBackoff::default());
// All operations will be retried if the error is retryable
let _ = op.object("test_file").read();