pub struct Object { /* private fields */ }
Expand description

Handler for all object related operations.

Implementations

Creates a new Object.

Read the whole object into a bytes.

This function will allocate a new bytes internally. For more precise memory control or reading data lazily, please use Object::reader

Examples
let bs = o.read().await?;

Read the specified range of object into a bytes.

This function will allocate a new bytes internally. For more precise memory control or reading data lazily, please use Object::range_reader

Examples
let bs = o.range_read(1024..2048).await?;

Create a new reader which can read the whole object.

Examples
let r = o.reader().await?;

Create a new reader which can read the whole object.

Examples
let r = o.range_reader(1024..2048).await?;

Write bytes into object.

Notes
  • Write will make sure all bytes has been written, or an error will be returned.
Examples
use bytes::Bytes;

let o = op.object("path/to/file");
let _ = o.write(vec![0; 4096]).await?;

Create a new writer which can write data into the object.

Examples
use bytes::Bytes;

let op = Operator::new(memory::Backend::build().finish().await?);
let o = op.object("path/to/file");
let mut w = o.writer(4096).await?;
w.write(&[1; 4096]);
w.close();

Delete object.

Notes
  • Delete not existing error won’t return errors.
Examples
op.object("test").delete().await?;

Get current object’s metadata.

Examples
use std::io::ErrorKind;
if let Err(e) = op.object("test").metadata().await {
    if e.kind() == ErrorKind::NotFound {
        println!("object not exist")
    }
}

Use local cached metadata if possible.

Example
use opendal::services::memory;
use anyhow::Result;
use futures::io;
use opendal::Operator;


#[tokio::main]
async fn main() -> Result<()> {
    let op = Operator::new(memory::Backend::build().finish().await?);
    let mut o = op.object("test");

    o.metadata_cached().await;
    // The second call to metadata_cached will have no cost.
    o.metadata_cached().await;

    Ok(())
}

Check if this object exist or not.

Example
use opendal::services::memory;
use anyhow::Result;
use futures::io;
use opendal::Operator;


#[tokio::main]
async fn main() -> Result<()> {
    let op = Operator::new(memory::Backend::build().finish().await?);
    let _ = op.object("test").is_exist().await?;

    Ok(())
}

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Applies the Compat adapter by value. Read more

Applies the Compat adapter by shared reference. Read more

Applies the Compat adapter by mutable reference. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more