file_operation/delete/async/fn.rs
1use std::path::Path;
2use tokio::fs::{remove_dir_all, remove_file};
3use tokio::io::Error;
4
5/// Asynchronously deletes a file at the given path.
6///
7/// - `path`: The file path to delete.
8///
9/// - Returns: `Ok(())` if the file was deleted successfully, or an `Err` with the error details.
10pub async fn async_delete_file(path: &str) -> Result<(), Error> {
11 remove_file(path).await
12}
13
14/// Asynchronously deletes a directory and all its contents.
15///
16/// - `path`: The directory path to delete.
17///
18/// - Returns: `Ok(())` if the directory and its contents were deleted successfully, or an `Err` with the error details.
19pub async fn async_delete_dir(path: &str) -> Result<(), Error> {
20 let dir_path: &Path = Path::new(path);
21 remove_dir_all(dir_path).await?;
22 Ok(())
23}