pub struct Object { /* private fields */ }
Expand description
Handler for all object related operations.
Implementations
sourceimpl Object
impl Object
sourcepub async fn read(&self) -> Result<Vec<u8>>
pub async fn read(&self) -> Result<Vec<u8>>
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?;
sourcepub async fn range_read(&self, range: impl RangeBounds<u64>) -> Result<Vec<u8>>
pub async fn range_read(&self, range: impl RangeBounds<u64>) -> Result<Vec<u8>>
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?;
sourcepub async fn range_reader(
&self,
range: impl RangeBounds<u64>
) -> Result<impl BytesRead>
pub async fn range_reader(
&self,
range: impl RangeBounds<u64>
) -> Result<impl BytesRead>
Create a new reader which can read the whole object.
Examples
let r = o.range_reader(1024..2048).await?;
sourcepub async fn writer(&self, size: u64) -> Result<impl BytesWrite>
pub async fn writer(&self, size: u64) -> Result<impl BytesWrite>
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();
sourcepub async fn metadata(&self) -> Result<Metadata>
pub async fn metadata(&self) -> Result<Metadata>
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")
}
}
sourcepub async fn metadata_cached(&mut self) -> Result<&Metadata>
pub async fn metadata_cached(&mut self) -> Result<&Metadata>
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(())
}
sourcepub async fn is_exist(&self) -> Result<bool>
pub async fn is_exist(&self) -> Result<bool>
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
Auto Trait Implementations
impl !RefUnwindSafe for Object
impl Send for Object
impl Sync for Object
impl Unpin for Object
impl !UnwindSafe for Object
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more