pub struct Operator { /* private fields */ }
Expand description
User-facing APIs for object and object streams.
Implementations§
source§impl Operator
impl Operator
sourcepub fn new(accessor: impl Accessor) -> Self
pub fn new(accessor: impl Accessor) -> Self
Create a new operator.
Examples
Read more backend init examples in examples.
#[tokio::main]
async fn main() -> Result<()> {
// Create fs backend builder.
let mut builder = fs::Builder::default();
// Set the root for fs, all operations will happen under this root.
//
// NOTE: the root must be absolute path.
builder.root("/tmp");
// Build an `Operator` to start operating the storage.
let op: Operator = Operator::new(builder.build()?);
// Create an object handle to start operation on object.
let _: Object = op.object("test_file");
Ok(())
}
sourcepub fn from_iter(
scheme: Scheme,
it: impl Iterator<Item = (String, String)> + 'static
) -> Result<Self>
pub fn from_iter(
scheme: Scheme,
it: impl Iterator<Item = (String, String)> + 'static
) -> Result<Self>
Create a new operator from iter.
Please refer different backends for detailed config options.
Behavior
- All input key must be
lower_case
- Boolean values will be checked by its existences and non-empty value.
on
,yes
,true
,off
,no
,false
will all be treated astrue
To disable a flag, please set value to empty.
Examples
#[tokio::main]
async fn main() -> Result<()> {
let op: Operator = Operator::from_iter(
Scheme::Fs,
[("root".to_string(), "/tmp".to_string())].into_iter(),
)?;
// Create an object handle to start operation on object.
let _: Object = op.object("test_file");
Ok(())
}
sourcepub fn from_env(scheme: Scheme) -> Result<Self>
pub fn from_env(scheme: Scheme) -> Result<Self>
Create a new operator from env.
Behavior
- Environment keys are case-insensitive, they will be converted to lower case internally.
- Environment values are case-sensitive, no sanity will be executed on them.
- Boolean values will be checked by its existences and non-empty value.
on
,yes
,true
,off
,no
,false
will all be treated astrue
To disable a flag, please set value to empty.
Examples
Setting environment:
export OPENDAL_FS_ROOT=/tmp
Please refer different backends for detailed config options.
#[tokio::main]
async fn main() -> Result<()> {
// Build an Operator to start operating the storage
let op: Operator = Operator::from_env(Scheme::Fs)?;
// Create an object handle to start operation on object.
let _: Object = op.object("test_file");
Ok(())
}
sourcepub fn layer(self, layer: impl Layer) -> Self
pub fn layer(self, layer: impl Layer) -> Self
Create a new layer.
Examples
This examples needs feature retry
enabled.
# use std::sync::Arc;
# use anyhow::Result;
# use opendal::services::fs;
# use opendal::services::fs::Builder;
use opendal::Operator;
use opendal::Layer;
# #[tokio::main]
# async fn main() -> Result<()> {
let accessor = fs::Backend::build().finish().await?;
let op = Operator::new(accessor).layer(new_layer);
// All operations will go through the new_layer
let _ = op.object("test_file").read();
# Ok(())
# }
sourcepub fn inner(&self) -> Arc<dyn Accessor>
pub fn inner(&self) -> Arc<dyn Accessor>
Get inner accessor.
This function should only be used by developers to implement layers.
sourcepub fn is_poisoned(&self) -> bool
pub fn is_poisoned(&self) -> bool
is_poisoned will check whether this operator has been poisoned.
Notes
Operator
will be shared across catch_unwind
boundary. But we can’t
make sure that all accessor is UnwindSafe
. So we add a poison flag to
mark whether Operator
has been dropped during panic.
After feature unwind-safe
has been enabled, users can use is_poisoned
to check whether thread panic has happened during operator’s dropping.
sourcepub fn metadata(&self) -> OperatorMetadata
pub fn metadata(&self) -> OperatorMetadata
Get metadata of underlying accessor.
Examples
use opendal::Operator;
use opendal::Scheme;
let op = Operator::from_env(Scheme::Fs)?;
let meta = op.metadata();
sourcepub fn batch(&self) -> BatchOperator
pub fn batch(&self) -> BatchOperator
Create a new batch operator handle to take batch operations
like walk
and remove
.