s3/bucket/
head.rs

1use crate::bucket::*;
2use crate::command::Command;
3use crate::request::RequestImpl;
4
5impl Bucket {
6    /// Head object from S3.
7    ///
8    /// # Example:
9    ///
10    /// ```no_run
11    /// use s3::bucket::Bucket;
12    /// use s3::creds::Credentials;
13    /// use anyhow::Result;
14    ///
15    /// # #[tokio::main]
16    /// # async fn main() -> Result<()> {
17    ///
18    /// let bucket_name = "rust-s3-test";
19    /// let region = "us-east-1".parse()?;
20    /// let credentials = Credentials::default()?;
21    /// let bucket = Bucket::new(bucket_name, region, credentials)?;
22    ///
23    /// let (head_object_result, code) = bucket.head_object("/test.png").await?;
24    /// #
25    /// # Ok(())
26    /// # }
27    /// ```
28    pub async fn head_object<S: AsRef<str>>(
29        &self,
30        path: S,
31    ) -> Result<(HeadObjectResult, u16), S3Error> {
32        let command = Command::HeadObject;
33        let request = RequestImpl::new(self, path.as_ref(), command)?;
34        let (headers, status) = request.response_header().await?;
35        let header_object = HeadObjectResult::from(&headers);
36        Ok((header_object, status))
37    }
38}