Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): impl delete_with on blocking operator #2633

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions core/src/types/operator/blocking_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions core/src/types/operator/operator_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}