pub trait PathExt {
Show 17 methods
// Required methods
fn into_path(self) -> Result<PathBuf, SoftPathError>;
fn exists(&self) -> Result<bool, SoftPathError>;
fn is_file(&self) -> Result<bool, SoftPathError>;
fn is_dir(&self) -> Result<bool, SoftPathError>;
fn create_file(&self) -> Result<(), SoftPathError>;
fn create_dir_all(&self) -> Result<(), SoftPathError>;
fn remove(&self) -> Result<(), SoftPathError>;
fn read_to_string(&self) -> Result<String, SoftPathError>;
fn write_string(&self, contents: &str) -> Result<(), SoftPathError>;
fn copy_to<P: AsRef<Path>>(&self, dest: P) -> Result<(), SoftPathError>;
fn move_to<P: AsRef<Path>>(&self, dest: P) -> Result<(), SoftPathError>;
fn is_empty(&self) -> Result<bool, SoftPathError>;
fn is_hidden(&self) -> Result<bool, SoftPathError>;
fn file_name(&self) -> Result<Option<String>, SoftPathError>;
fn extension(&self) -> Result<Option<String>, SoftPathError>;
fn parent_name(&self) -> Result<Option<String>, SoftPathError>;
fn absolute(&self) -> Result<PathBuf, SoftPathError>;
}Expand description
A trait for ergonomic, human-friendly path manipulation.
Required Methods§
Sourcefn into_path(self) -> Result<PathBuf, SoftPathError>
fn into_path(self) -> Result<PathBuf, SoftPathError>
Converts the path into a PathBuf.
§Errors
Returns an error if:
- The path contains invalid UTF-8
- Home directory expansion is requested but the home directory cannot be determined
Sourcefn exists(&self) -> Result<bool, SoftPathError>
fn exists(&self) -> Result<bool, SoftPathError>
Returns true if the path exists.
§Errors
Returns an error if:
- The path contains invalid characters
- The path contains directory traversal attempts
- The path contains symlink cycles
Sourcefn is_file(&self) -> Result<bool, SoftPathError>
fn is_file(&self) -> Result<bool, SoftPathError>
Returns true if the path points to a regular file.
§Errors
Returns an error if:
- The path contains invalid characters
- The path contains directory traversal attempts
- The path contains symlink cycles
Sourcefn is_dir(&self) -> Result<bool, SoftPathError>
fn is_dir(&self) -> Result<bool, SoftPathError>
Returns true if the path points to a directory.
§Errors
Returns an error if:
- The path contains invalid characters
- The path contains directory traversal attempts
- The path contains symlink cycles
Sourcefn create_file(&self) -> Result<(), SoftPathError>
fn create_file(&self) -> Result<(), SoftPathError>
Creates a new, empty file at this path.
§Errors
Returns an error if:
- The file already exists
- The user lacks permissions
- Any parent directories are missing
Sourcefn create_dir_all(&self) -> Result<(), SoftPathError>
fn create_dir_all(&self) -> Result<(), SoftPathError>
Creates all parent directories if they are missing.
§Errors
Returns an error if:
- The user lacks permissions
- Any parent component is not a directory
Sourcefn remove(&self) -> Result<(), SoftPathError>
fn remove(&self) -> Result<(), SoftPathError>
Removes a file or directory at this path.
§Errors
Returns an error if:
- The path does not exist
- The user lacks permissions
- The path is a non-empty directory
Sourcefn read_to_string(&self) -> Result<String, SoftPathError>
fn read_to_string(&self) -> Result<String, SoftPathError>
Reads the entire file into a string.
§Errors
Returns an error if:
- The path does not exist
- The path is not a file
- The file cannot be read
- The file contains invalid UTF-8
Sourcefn write_string(&self, contents: &str) -> Result<(), SoftPathError>
fn write_string(&self, contents: &str) -> Result<(), SoftPathError>
Writes a string slice to a file.
§Errors
Returns an error if:
- The file cannot be created
- The user lacks permissions
- Any parent directories are missing
Sourcefn copy_to<P: AsRef<Path>>(&self, dest: P) -> Result<(), SoftPathError>
fn copy_to<P: AsRef<Path>>(&self, dest: P) -> Result<(), SoftPathError>
Copies the file to a new path.
§Errors
Returns an error if:
- The source path does not exist
- The destination path already exists
- The user lacks permissions
- Any parent directories of the destination are missing
Sourcefn move_to<P: AsRef<Path>>(&self, dest: P) -> Result<(), SoftPathError>
fn move_to<P: AsRef<Path>>(&self, dest: P) -> Result<(), SoftPathError>
Moves the file or directory to a new path.
§Errors
Returns an error if:
- The source path does not exist
- The destination path already exists
- The user lacks permissions
Sourcefn is_empty(&self) -> Result<bool, SoftPathError>
fn is_empty(&self) -> Result<bool, SoftPathError>
Returns true if the path points to an empty file or directory.
§Errors
Returns an error if:
- The path does not exist
- The user lacks permissions to read the path
Returns true if the path is hidden (platform-specific implementation).
§Errors
Returns an error if:
- The path does not exist
- The user lacks permissions to read the path attributes
Sourcefn file_name(&self) -> Result<Option<String>, SoftPathError>
fn file_name(&self) -> Result<Option<String>, SoftPathError>
Returns the file name as a String, or None if the path terminates in ‘..’ or ‘.’.
§Errors
Returns an error if:
- The path contains invalid characters
- The path contains directory traversal attempts
- The path contains symlink cycles
Sourcefn extension(&self) -> Result<Option<String>, SoftPathError>
fn extension(&self) -> Result<Option<String>, SoftPathError>
Returns the extension of the file as a String, or None if there is no extension.
§Errors
Returns an error if:
- The path contains invalid characters
- The path contains directory traversal attempts
- The path contains symlink cycles
Sourcefn parent_name(&self) -> Result<Option<String>, SoftPathError>
fn parent_name(&self) -> Result<Option<String>, SoftPathError>
Returns the name of the parent directory as a String, or None if there is no parent.
§Errors
Returns an error if:
- The path contains invalid characters
- The path contains directory traversal attempts
- The path contains symlink cycles
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.