pub trait FsExt: Fs {
// Provided methods
fn is_file(&self, path: &Path) -> Result<bool, FsError> { ... }
fn is_dir(&self, path: &Path) -> Result<bool, FsError> { ... }
fn is_symlink(&self, path: &Path) -> Result<bool, FsError> { ... }
fn file_size(&self, path: &Path) -> Result<u64, FsError> { ... }
}Expand description
Extension methods for any filesystem backend.
Provides convenience methods not in the core traits but commonly needed. All methods have default implementations, so backends get them automatically.
§Example
use anyfs_backend::{Fs, FsExt, FsError};
use std::path::Path;
fn check_paths<B: Fs>(backend: &B) -> Result<(), FsError> {
// FsExt methods are available on any Fs backend
if backend.is_file(Path::new("/config.json"))? {
println!("Config exists!");
}
if backend.is_dir(Path::new("/data"))? {
println!("Data directory exists!");
}
Ok(())
}Provided Methods§
Sourcefn is_file(&self, path: &Path) -> Result<bool, FsError>
fn is_file(&self, path: &Path) -> Result<bool, FsError>
Check if the path points to a regular file.
Returns Ok(false) if the path doesn’t exist (not an error).
Returns Err only for actual I/O errors (permission denied, etc.).
§Example
use anyfs_backend::{Fs, FsExt, FsError};
use std::path::Path;
fn process_file<B: Fs>(backend: &B, path: &Path) -> Result<(), FsError> {
if backend.is_file(path)? {
let data = backend.read(path)?;
// Process the file...
}
Ok(())
}Sourcefn is_dir(&self, path: &Path) -> Result<bool, FsError>
fn is_dir(&self, path: &Path) -> Result<bool, FsError>
Check if the path points to a directory.
Returns Ok(false) if the path doesn’t exist (not an error).
Returns Err only for actual I/O errors (permission denied, etc.).
§Example
use anyfs_backend::{Fs, FsExt, FsError};
use std::path::Path;
fn ensure_dir<B: Fs>(backend: &B, path: &Path) -> Result<(), FsError> {
if !backend.is_dir(path)? {
backend.create_dir_all(path)?;
}
Ok(())
}Sourcefn is_symlink(&self, path: &Path) -> Result<bool, FsError>
fn is_symlink(&self, path: &Path) -> Result<bool, FsError>
Check if the path points to a symbolic link.
Returns Ok(false) if the path doesn’t exist (not an error).
Returns Err only for actual I/O errors.
§Note
This method uses regular metadata() which follows symlinks.
For backends implementing FsLink, consider using
symlink_metadata() for more accurate symlink detection.
§Example
use anyfs_backend::{Fs, FsExt, FsError};
use std::path::Path;
fn check_link<B: Fs>(backend: &B, path: &Path) -> Result<bool, FsError> {
backend.is_symlink(path)
}Sourcefn file_size(&self, path: &Path) -> Result<u64, FsError>
fn file_size(&self, path: &Path) -> Result<u64, FsError>
Get the size of a file in bytes.
Convenience method that extracts just the size from metadata.
§Errors
Returns FsError::NotFound if the path doesn’t exist.
§Example
use anyfs_backend::{Fs, FsExt, FsError};
use std::path::Path;
fn check_size<B: Fs>(backend: &B, path: &Path) -> Result<u64, FsError> {
backend.file_size(path)
}