Skip to content

Commit 4eadb78

Browse files
authored
feat(core): impl delete_with on blocking operator (#2633)
feat(core): delete_with on blocking operator Signed-off-by: suyanhanx <[email protected]>
1 parent c0205fd commit 4eadb78

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

core/src/types/operator/blocking_operator.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,11 +673,43 @@ impl BlockingOperator {
673673
/// # }
674674
/// ```
675675
pub fn delete(&self, path: &str) -> Result<()> {
676+
self.delete_with(path).call()?;
677+
678+
Ok(())
679+
}
680+
681+
/// Delete given path with options.
682+
///
683+
/// # Notes
684+
///
685+
/// - Delete not existing error won't return errors.
686+
///
687+
/// # Examples
688+
///
689+
/// ```no_run
690+
/// # use anyhow::Result;
691+
/// # use futures::io;
692+
/// # use opendal::BlockingOperator;
693+
/// # fn test(op: BlockingOperator) -> Result<()> {
694+
/// let _ = op
695+
/// .delete_with("path/to/file")
696+
/// .version("example_version").call()?;
697+
/// # Ok(())
698+
/// # }
699+
/// ```
700+
pub fn delete_with(&self, path: &str) -> FunctionDelete {
676701
let path = normalize_path(path);
677702

678-
let _ = self.inner().blocking_delete(&path, OpDelete::new())?;
703+
FunctionDelete(OperatorFunction::new(
704+
self.inner().clone(),
705+
path,
706+
OpDelete::new(),
707+
|inner, path, args| {
708+
let _ = inner.blocking_delete(&path, args)?;
679709

680-
Ok(())
710+
Ok(())
711+
},
712+
))
681713
}
682714

683715
/// remove will remove files via the given paths.

core/src/types/operator/operator_functions.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,22 @@ impl FunctionWrite {
9595
self.0.call()
9696
}
9797
}
98+
99+
/// Function that generated by [`BlockingOperator::delete_with`].
100+
///
101+
/// Users can add more options by public functions provided by this struct.
102+
pub struct FunctionDelete(pub(crate) OperatorFunction<OpDelete, ()>);
103+
104+
impl FunctionDelete {
105+
/// Set the version for this operation.
106+
pub fn version(mut self, v: &str) -> Self {
107+
self.0 = self.0.map_args(|args| args.with_version(v));
108+
self
109+
}
110+
111+
/// Call the function to consume all the input and generate a
112+
/// result.
113+
pub fn call(self) -> Result<()> {
114+
self.0.call()
115+
}
116+
}

0 commit comments

Comments
 (0)