This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 4eadb789a feat(core): impl `delete_with` on blocking operator (#2633)
4eadb789a is described below

commit 4eadb789a014fe644fc76ffa2199edd71a137eac
Author: Suyan <[email protected]>
AuthorDate: Thu Jul 13 16:46:53 2023 +0800

    feat(core): impl `delete_with` on blocking operator (#2633)
    
    feat(core): delete_with on blocking operator
    
    Signed-off-by: suyanhanx <[email protected]>
---
 core/src/types/operator/blocking_operator.rs  | 36 +++++++++++++++++++++++++--
 core/src/types/operator/operator_functions.rs | 19 ++++++++++++++
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/core/src/types/operator/blocking_operator.rs 
b/core/src/types/operator/blocking_operator.rs
index 57144817e..e6badc721 100644
--- a/core/src/types/operator/blocking_operator.rs
+++ b/core/src/types/operator/blocking_operator.rs
@@ -673,11 +673,43 @@ impl BlockingOperator {
     /// # }
     /// ```
     pub fn delete(&self, path: &str) -> Result<()> {
+        self.delete_with(path).call()?;
+
+        Ok(())
+    }
+
+    /// Delete given path with options.
+    ///
+    /// # Notes
+    ///
+    /// - Delete not existing error won't return errors.
+    ///
+    /// # Examples
+    ///
+    /// ```no_run
+    /// # use anyhow::Result;
+    /// # use futures::io;
+    /// # use opendal::BlockingOperator;
+    /// # fn test(op: BlockingOperator) -> Result<()> {
+    /// let _ = op
+    ///     .delete_with("path/to/file")
+    ///     .version("example_version").call()?;
+    /// # Ok(())
+    /// # }
+    /// ```
+    pub fn delete_with(&self, path: &str) -> FunctionDelete {
         let path = normalize_path(path);
 
-        let _ = self.inner().blocking_delete(&path, OpDelete::new())?;
+        FunctionDelete(OperatorFunction::new(
+            self.inner().clone(),
+            path,
+            OpDelete::new(),
+            |inner, path, args| {
+                let _ = inner.blocking_delete(&path, args)?;
 
-        Ok(())
+                Ok(())
+            },
+        ))
     }
 
     /// remove will remove files via the given paths.
diff --git a/core/src/types/operator/operator_functions.rs 
b/core/src/types/operator/operator_functions.rs
index 282d097c2..0d97e2fed 100644
--- a/core/src/types/operator/operator_functions.rs
+++ b/core/src/types/operator/operator_functions.rs
@@ -95,3 +95,22 @@ impl FunctionWrite {
         self.0.call()
     }
 }
+
+/// Function that generated by [`BlockingOperator::delete_with`].
+///
+/// Users can add more options by public functions provided by this struct.
+pub struct FunctionDelete(pub(crate) OperatorFunction<OpDelete, ()>);
+
+impl FunctionDelete {
+    /// Set the version for this operation.
+    pub fn version(mut self, v: &str) -> Self {
+        self.0 = self.0.map_args(|args| args.with_version(v));
+        self
+    }
+
+    /// Call the function to consume all the input and generate a
+    /// result.
+    pub fn call(self) -> Result<()> {
+        self.0.call()
+    }
+}

Reply via email to