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/// # Arguments
8///
9/// - `&str` - The file path to delete.
10///
11/// # Returns
12///
13/// - `Result<(), std::io::Error>` - Ok if the file was deleted successfully, Err with error details otherwise.
14pub async fn async_delete_file(path: &str) -> Result<(), Error> {
15    remove_file(path).await
16}
17
18/// Asynchronously deletes a directory and all its contents.
19///
20/// # Arguments
21///
22/// - `&str` - The directory path to delete.
23///
24/// # Returns
25///
26/// - `Result<(), std::io::Error>` - Ok if the directory was deleted successfully, Err with error details otherwise.
27pub async fn async_delete_dir(path: &str) -> Result<(), Error> {
28    let dir_path: &Path = Path::new(path);
29    remove_dir_all(dir_path).await?;
30    Ok(())
31}