pub struct Operator { /* private fields */ }
Expand description
User-facing APIs for object and object streams.
Implementations
sourceimpl Operator
impl Operator
sourcepub fn new(accessor: impl Accessor + 'static) -> Self
pub fn new(accessor: impl Accessor + 'static) -> 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");
// `Accessor` provides the low level APIs, we will use `Operator` normally.
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)>
) -> Result<Self>
pub fn from_iter(
scheme: Scheme,
it: impl Iterator<Item = (String, String)>
) -> 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<()> {
// `Accessor` provides the low level APIs, we will use `Operator` normally.
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 opendal::Operator;
use opendal::Layer;
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();
sourcepub fn metadata(&self) -> AccessorMetadata
pub fn metadata(&self) -> AccessorMetadata
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
.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Operator
impl Send for Operator
impl Sync for Operator
impl Unpin for Operator
impl !UnwindSafe for Operator
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more