opendal/raw/oio/delete/
one_shot_delete.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use std::future::Future;
19
20use crate::raw::*;
21use crate::*;
22
23/// OneShotDelete is used to implement [`oio::Delete`] based on one shot operation.
24///
25/// OneShotDeleter will perform delete operation while calling `close`.
26pub trait OneShotDelete: Send + Sync + Unpin + 'static {
27    /// delete_once delete one path at once.
28    ///
29    /// Implementations should make sure that the data is deleted correctly at once.
30    fn delete_once(
31        &self,
32        path: String,
33        args: OpDelete,
34    ) -> impl Future<Output = Result<()>> + MaybeSend;
35}
36
37/// OneShotDelete is used to implement [`oio::Delete`] based on one shot.
38pub struct OneShotDeleter<D> {
39    inner: D,
40}
41
42impl<D> OneShotDeleter<D> {
43    /// Create a new one shot deleter.
44    pub fn new(inner: D) -> Self {
45        Self { inner }
46    }
47}
48
49impl<D: OneShotDelete> oio::Delete for OneShotDeleter<D> {
50    async fn delete(&mut self, path: &str, args: OpDelete) -> Result<()> {
51        self.inner.delete_once(path.to_string(), args).await
52    }
53
54    async fn close(&mut self) -> Result<()> {
55        Ok(())
56    }
57}