aliyun_oss_rs/object/
del_object.rs

1use crate::{
2    Error,
3    error::normal_error,
4    request::{Oss, OssRequest},
5};
6use http::Method;
7
8/// Delete the specified object
9///
10/// When deleting, OSS does not check whether the object exists; a valid request always succeeds
11///
12/// If versioning is enabled, the response is meaningful. Please refer to the documentation for delete markers and version IDs
13///
14/// See the [Alibaba Cloud documentation](https://help.aliyun.com/document_detail/31982.html) for details
15pub struct DelObject {
16    req: OssRequest,
17}
18impl DelObject {
19    pub(super) fn new(oss: Oss) -> Self {
20        DelObject {
21            req: OssRequest::new(oss, Method::DELETE),
22        }
23    }
24    /// Send the request
25    ///
26    /// The return value is meaningful only when versioning is enabled
27    ///
28    /// - Return value 0: x-oss-delete-marker flag
29    /// - Return value 1: Version ID. If no version ID is specified when deleting, this is the version ID of the new delete marker; otherwise, it is the specified version ID
30    pub async fn send(self) -> Result<(), Error> {
31        // Build the HTTP request
32        let response = self.req.send_to_oss()?.await?;
33        // Parse the response
34        let status_code = response.status();
35        match status_code {
36            code if code.is_success() => Ok(()),
37            _ => Err(normal_error(response).await),
38        }
39    }
40}