Skip to content

Commit

Permalink
Add examples
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo committed Feb 22, 2023
1 parent d0e97e1 commit 01a0cca
Showing 1 changed file with 89 additions and 10 deletions.
99 changes: 89 additions & 10 deletions src/object/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,18 +1237,39 @@ impl Object {
///
/// # Examples
///
/// ## Query already cached metadata
///
/// By query metadata with `None`, we can only query in-memory metadata
/// cache. In this way, we can make sure that no API call will send.
///
/// ```
/// # use anyhow::Result;
/// # use futures::io;
/// # use opendal::Operator;
/// use opendal::ErrorKind;
/// #
/// # #[tokio::main]
/// # async fn test(op: Operator) -> Result<()> {
/// let meta = op.object("test").metadata(None).await?;
/// let _ = meta.content_length();
/// let _ = meta.content_type();
/// # Ok(())
/// # }
/// ```
///
/// ## Query content length and content type
///
/// ```
/// # use anyhow::Result;
/// # use opendal::Operator;
/// use opendal::ErrorKind;
/// use opendal::ObjectMetadataKey;
/// #
/// # #[tokio::main]
/// # async fn test(op: Operator) -> Result<()> {
/// let meta = op
/// .object("test")
/// .metadata({
/// use opendal::ObjectMetadataKey::*;
/// use ObjectMetadataKey::*;
/// ContentLength | ContentType
/// })
/// .await?;
Expand All @@ -1257,6 +1278,28 @@ impl Object {
/// # Ok(())
/// # }
/// ```
///
/// ## Query all metadata
///
/// By query metadata with `Complete`, we can make sure that we have fetched all metadata of this object.
///
/// ```
/// # use anyhow::Result;
/// # use opendal::Operator;
/// use opendal::ErrorKind;
/// use opendal::ObjectMetadataKey;
/// #
/// # #[tokio::main]
/// # async fn test(op: Operator) -> Result<()> {
/// let meta = op
/// .object("test")
/// .metadata({ ObjectMetadataKey::Complete })
/// .await?;
/// let _ = meta.content_length();
/// let _ = meta.content_type();
/// # Ok(())
/// # }
/// ```
pub async fn metadata(
&mut self,
flags: impl Into<FlagSet<ObjectMetadataKey>>,
Expand Down Expand Up @@ -1299,21 +1342,57 @@ impl Object {
///
/// # Examples
///
/// ## Query already cached metadata
///
/// By query metadata with `None`, we can only query in-memory metadata
/// cache. In this way, we can make sure that no API call will send.
///
/// ```
/// # use anyhow::Result;
/// # use futures::io;
/// # use opendal::Operator;
/// use opendal::ErrorKind;
/// #
/// # #[tokio::main]
/// # async fn test(op: Operator) -> Result<()> {
/// # fn test(op: Operator) -> Result<()> {
/// let meta = op.object("test").blocking_metadata(None)?;
/// let _ = meta.content_length();
/// let _ = meta.content_type();
/// # Ok(())
/// # }
/// ```
///
/// ## Query content length and content type
///
/// ```
/// # use anyhow::Result;
/// # use opendal::Operator;
/// use opendal::ErrorKind;
/// use opendal::ObjectMetadataKey;
/// #
/// # fn test(op: Operator) -> Result<()> {
/// let meta = op.object("test").blocking_metadata({
/// use ObjectMetadataKey::*;
/// ContentLength | ContentType
/// })?;
/// let _ = meta.content_length();
/// let _ = meta.content_type();
/// # Ok(())
/// # }
/// ```
///
/// ## Query all metadata
///
/// By query metadata with `Complete`, we can make sure that we have fetched all metadata of this object.
///
/// ```
/// # use anyhow::Result;
/// # use opendal::Operator;
/// use opendal::ErrorKind;
/// use opendal::ObjectMetadataKey;
/// #
/// # fn test(op: Operator) -> Result<()> {
/// let meta = op
/// .object("test")
/// .metadata({
/// use opendal::ObjectMetadataKey::*;
/// ContentLength | ContentType
/// })
/// .await?;
/// .blocking_metadata({ ObjectMetadataKey::Complete })?;
/// let _ = meta.content_length();
/// let _ = meta.content_type();
/// # Ok(())
Expand Down

1 comment on commit 01a0cca

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for opendal ready!

✅ Preview
https://opendal-nyrfwvkht-databend.vercel.app
https://opendal-git-polish.vercel.app

Built with commit 01a0cca.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.