pub trait AutoPath {
// Required methods
fn auto_create_dir(&self) -> AnyResult<()>;
fn auto_remove_dir(&self) -> AnyResult<()>;
fn auto_create_file<S: AsRef<str>>(&self, content: S) -> AnyResult<()>;
fn auto_remove_file(&self) -> AnyResult<()>;
fn a_auto_create_dir<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnyResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn a_auto_remove_dir<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnyResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn a_auto_create_file<'life0, 'async_trait>(
&'life0 self,
content: impl 'async_trait + AsRef<[u8]> + Send,
) -> Pin<Box<dyn Future<Output = AnyResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn a_auto_remove_file<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnyResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
自动检查和操作文件系统路径
Required Methods§
Sourcefn auto_create_dir(&self) -> AnyResult<()>
fn auto_create_dir(&self) -> AnyResult<()>
自动创建目录
§Example
use std::path::Path;
use e_utils::fs::AutoPath;
let path = Path::new("test_dir");
path.auto_create_dir().unwrap();
assert!(path.exists() && path.is_dir());
// 清理
std::fs::remove_dir(path).unwrap();Sourcefn auto_remove_dir(&self) -> AnyResult<()>
fn auto_remove_dir(&self) -> AnyResult<()>
自动移除目录
§Example
use std::path::Path;
use e_utils::fs::AutoPath;
let path = Path::new("test_remove_dir");
std::fs::create_dir(path).unwrap();
assert!(path.exists());
path.auto_remove_dir().unwrap();
assert!(!path.exists());Sourcefn auto_create_file<S: AsRef<str>>(&self, content: S) -> AnyResult<()>
fn auto_create_file<S: AsRef<str>>(&self, content: S) -> AnyResult<()>
自动创建文件
§Example
use std::path::Path;
use e_utils::fs::AutoPath;
let path = Path::new("test_file.txt");
path.auto_create_file("Hello, World!").unwrap();
assert!(path.exists() && path.is_file());
let content = std::fs::read_to_string(path).unwrap();
assert_eq!(content, "Hello, World!");
// 清理
std::fs::remove_file(path).unwrap();Sourcefn auto_remove_file(&self) -> AnyResult<()>
fn auto_remove_file(&self) -> AnyResult<()>
自动移除文件
§Example
use std::path::Path;
use e_utils::fs::AutoPath;
let path = Path::new("test_remove_file.txt");
std::fs::write(path, "Test content").unwrap();
assert!(path.exists());
path.auto_remove_file().unwrap();
assert!(!path.exists());Sourcefn a_auto_create_dir<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnyResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn a_auto_create_dir<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnyResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Asynchronously creates a directory.
§Example
use std::path::Path;
use e_utils::fs::AutoPath;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = Path::new("test_async_dir");
path.a_auto_create_dir().await?;
assert!(path.exists() && path.is_dir());
// Clean up
tokio::fs::remove_dir(path).await?;
Ok(())
}Sourcefn a_auto_remove_dir<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnyResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn a_auto_remove_dir<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnyResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Asynchronously removes a directory.
§Example
use std::path::Path;
use e_utils::fs::AutoPath;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = Path::new("test_async_remove_dir");
tokio::fs::create_dir(path).await?;
assert!(path.exists());
path.a_auto_remove_dir().await?;
assert!(!path.exists());
Ok(())
}Sourcefn a_auto_create_file<'life0, 'async_trait>(
&'life0 self,
content: impl 'async_trait + AsRef<[u8]> + Send,
) -> Pin<Box<dyn Future<Output = AnyResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn a_auto_create_file<'life0, 'async_trait>(
&'life0 self,
content: impl 'async_trait + AsRef<[u8]> + Send,
) -> Pin<Box<dyn Future<Output = AnyResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Asynchronously creates a file with the given content.
§Example
use std::path::Path;
use e_utils::fs::AutoPath;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = Path::new("test_async_file.txt");
path.a_auto_create_file("Hello, World!").await?;
assert!(path.exists() && path.is_file());
let content = tokio::fs::read_to_string(path).await?;
assert_eq!(content, "Hello, World!");
// Clean up
tokio::fs::remove_file(path).await?;
Ok(())
}Sourcefn a_auto_remove_file<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnyResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn a_auto_remove_file<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnyResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Asynchronously removes a file.
§Example
use std::path::Path;
use e_utils::fs::AutoPath;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = Path::new("test_async_remove_file.txt");
tokio::fs::write(path, "Test content").await?;
assert!(path.exists());
path.a_auto_remove_file().await?;
assert!(!path.exists());
Ok(())
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.