aliyun_oss_rs/bucket/
del_bucket.rs

1use crate::{
2    Error,
3    error::normal_error,
4    request::{Oss, OssRequest},
5};
6use http::Method;
7
8/// Delete a bucket
9///
10/// To prevent accidental deletions, OSS does not allow deleting a non-empty bucket
11///
12/// See the [Alibaba Cloud documentation](https://help.aliyun.com/document_detail/31973.html) for details
13pub struct DelBucket {
14    req: OssRequest,
15}
16impl DelBucket {
17    pub(super) fn new(oss: Oss) -> Self {
18        DelBucket {
19            req: OssRequest::new(oss, Method::DELETE),
20        }
21    }
22
23    pub async fn send(self) -> Result<(), Error> {
24        // Build the HTTP request
25        let response = self.req.send_to_oss()?.await?;
26        // Parse the response
27        let status_code = response.status();
28        match status_code {
29            code if code.is_success() => Ok(()),
30            _ => Err(normal_error(response).await),
31        }
32    }
33}