pub struct Operator { /* private fields */ }
Expand description
Operator is the user-facing APIs for object and object streams.
Operator needs to be built with Builder
.
Implementations§
source§impl Operator
impl Operator
sourcepub fn new<A: Accessor>(acc: A) -> OperatorBuilder<impl Accessor>
pub fn new<A: Accessor>(acc: A) -> OperatorBuilder<impl Accessor>
Create a new operator.
Examples
Read more backend init examples in examples.
use opendal::services::Fs;
use opendal::Builder;
use opendal::Operator;
#[tokio::main]
async fn main() -> Result<()> {
// Create fs backend builder.
let mut builder = Fs::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()?).finish();
// Create an object handle to start operation on object.
let _ = op.object("test_file");
Ok(())
}
sourcepub fn create<B: Builder>(ab: B) -> Result<OperatorBuilder<impl Accessor>>
pub fn create<B: Builder>(ab: B) -> Result<OperatorBuilder<impl Accessor>>
Create a new operator with input builder.
OpenDAL will call builder.build()
internally, so we don’t need
to import opendal::Builder
trait.
Examples
Read more backend init examples in examples.
use opendal::services::Fs;
use opendal::Operator;
#[tokio::main]
async fn main() -> Result<()> {
// Create fs backend builder.
let mut builder = Fs::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::create(builder)?.finish();
// Create an object handle to start operation on object.
let _ = op.object("test_file");
Ok(())
}
sourcepub fn from_map<B: Builder>(
map: HashMap<String, String>
) -> Result<OperatorBuilder<impl Accessor>>
pub fn from_map<B: Builder>( map: HashMap<String, String> ) -> Result<OperatorBuilder<impl Accessor>>
Create a new operator from given map.
use std::collections::HashMap;
use opendal::services::Fs;
use opendal::Operator;
#[tokio::main]
async fn main() -> Result<()> {
let map = HashMap::from([
// Set the root for fs, all operations will happen under this root.
//
// NOTE: the root must be absolute path.
("root".to_string(), "/tmp".to_string()),
]);
// Build an `Operator` to start operating the storage.
let op: Operator = Operator::from_map::<Fs>(map)?.finish();
// Create an object handle to start operation on object.
let _ = op.object("test_file");
Ok(())
}
sourcepub fn from_iter<B: Builder>(
iter: impl Iterator<Item = (String, String)>
) -> Result<OperatorBuilder<impl Accessor>>
pub fn from_iter<B: Builder>( iter: impl Iterator<Item = (String, String)> ) -> Result<OperatorBuilder<impl Accessor>>
Create a new operator from iter.
WARNING
It’s better to use from_map
. We may remove this API in the
future.
sourcepub fn from_env<B: Builder>() -> Result<OperatorBuilder<impl Accessor>>
pub fn from_env<B: Builder>() -> Result<OperatorBuilder<impl Accessor>>
Create a new operator from env.
WARNING
It’s better to use from_map
. We may remove this API in the
future.
sourcepub fn inner(&self) -> FusedAccessor
pub fn inner(&self) -> FusedAccessor
Get inner accessor.
This function should only be used by developers to implement layers.
sourcepub fn layer<L: Layer<FusedAccessor>>(self, layer: L) -> Self
pub fn layer<L: Layer<FusedAccessor>>(self, layer: L) -> Self
Create a new layer with dynamic dispatch.
Notes
OperatorBuilder::layer()
is using static dispatch which is zero
cost. Operator::layer()
is using dynamic dispatch which has a
bit runtime overhead with an extra vtable lookup and unable to
inline.
It’s always recommended to use OperatorBuilder::layer()
instead.
Examples
use opendal::layers::LoggingLayer;
use opendal::services::Fs;
use opendal::Operator;
let op = Operator::create(Fs::default())?.finish();
let op = op.layer(LoggingLayer::default());
// All operations will go through the new_layer
let _ = op.object("test_file").read().await?;
sourcepub fn metadata(&self) -> OperatorMetadata
pub fn metadata(&self) -> OperatorMetadata
sourcepub fn batch(&self) -> BatchOperator
pub fn batch(&self) -> BatchOperator
Create a new batch operator handle to take batch operations
like walk
and remove
.