pub struct FilePath { /* private fields */ }Expand description
A file path.
Implementations§
Source§impl FilePath
Read String
impl FilePath
Read String
Sourcepub fn read_as_string(&self) -> Result<String, Error>
pub fn read_as_string(&self) -> Result<String, Error>
Reads the file as a String.
Returns Ok(file_content).
Returns Err(FileNotFound) if the file did not exist.
Sourcepub fn read_as_string_if_exists(&self) -> Result<Option<String>, Error>
pub fn read_as_string_if_exists(&self) -> Result<Option<String>, Error>
Reads the file as a String if it exists.
Returns Ok(Some(file_content)).
Returns Ok(None) if the file did not exist.
Source§impl FilePath
Read Vec
impl FilePath
Read Vec
Sourcepub fn read_as_vec(&self) -> Result<Vec<u8>, Error>
pub fn read_as_vec(&self) -> Result<Vec<u8>, Error>
Reads the file as a Vec.
Returns Ok(file_content).
Returns Err(FileNotFound) if the file did not exist.
Sourcepub fn read_as_vec_if_exists(&self) -> Result<Option<Vec<u8>>, Error>
pub fn read_as_vec_if_exists(&self) -> Result<Option<Vec<u8>>, Error>
Reads the file as a Vec if it exists.
Returns Ok(Some(file_content)).
Returns Ok(None) if the file did not exist.
Source§impl FilePath
Write
impl FilePath
Write
Source§impl FilePath
Write Data
impl FilePath
Write Data
Sourcepub fn write_data<D>(&self, data: D) -> Result<(), Error>
pub fn write_data<D>(&self, data: D) -> Result<(), Error>
Writes the data to the file.
Returns Ok(()).
Returns Err(FileAlreadyExists) if the file already exists.
Source§impl FilePath
Write Empty
impl FilePath
Write Empty
Sourcepub fn write_empty(&self) -> Result<(), Error>
pub fn write_empty(&self) -> Result<(), Error>
Writes an empty file.
Returns Ok(()).
Returns Err(FileAlreadyExists) if the file already exists.
Sourcepub fn write_empty_if_not_exists(&self) -> Result<bool, Error>
pub fn write_empty_if_not_exists(&self) -> Result<bool, Error>
Writes an empty file if the file does not exist.
Returns Ok(true) if the file was written.
Returns Ok(false) if the file already exists.
Source§impl FilePath
Delete
impl FilePath
Delete
Sourcepub fn delete(&self) -> Result<(), Error>
pub fn delete(&self) -> Result<(), Error>
Deletes the file.
Returns Ok(()) if the file was deleted or if the file did not exist.
Sourcepub fn delete_if_exists(&self) -> Result<bool, Error>
pub fn delete_if_exists(&self) -> Result<bool, Error>
Deletes the file if it exists.
Returns Ok(true) if the file existed and was deleted.
Returns Ok(false) if the file did not exist.
Source§impl FilePath
Storage Path
impl FilePath
Storage Path
Sourcepub fn path(&self) -> &StoragePath
pub fn path(&self) -> &StoragePath
Gets the storage path.
Sourcepub fn to_path(self) -> StoragePath
pub fn to_path(self) -> StoragePath
Converts the file path to a storage path.
Source§impl FilePath
Clone
impl FilePath
Clone
Sourcepub fn clone_with_extra_capacity(&self, extra_capacity: usize) -> Self
pub fn clone_with_extra_capacity(&self, extra_capacity: usize) -> Self
Clones the path with the extra capacity.
Source§impl FilePath
Make Folder
impl FilePath
Make Folder
Sourcepub fn make_folder(self) -> FolderPath
pub fn make_folder(self) -> FolderPath
Makes the file a folder by appending a file-separator.
Source§impl FilePath
Extension
impl FilePath
Extension
Sourcepub fn extension(&self) -> Option<&str>
pub fn extension(&self) -> Option<&str>
Gets the file extension (the portion after the last . in the file name).
Returns None if there is no . in the file name.
Sourcepub fn dot_extension(&self) -> Option<&str>
pub fn dot_extension(&self) -> Option<&str>
Gets the file extension with the leading ..
Returns None if there is no . in the file name.
Methods from Deref<Target = StoragePath>§
Sourcepub fn file_separator(&self) -> char
pub fn file_separator(&self) -> char
Gets the file-separator.
Sourcepub fn clone_to_file(&self) -> Result<FilePath, Error>
pub fn clone_to_file(&self) -> Result<FilePath, Error>
Clones the path and converts it to a file path.
Returns Err if the path is not a file path.
Sourcepub fn clone_to_folder(&self) -> Result<FolderPath, Error>
pub fn clone_to_folder(&self) -> Result<FolderPath, Error>
Clones the path and converts it to a folder path.
Returns Err if the path is not a folder path.
Sourcepub fn clone_with_extra_capacity(&self, extra_capacity: usize) -> Self
pub fn clone_with_extra_capacity(&self, extra_capacity: usize) -> Self
Clones the path with the extra capacity.
Sourcepub fn clone_append<S>(&self, string: S) -> Self
pub fn clone_append<S>(&self, string: S) -> Self
Clones the path and appends the string.
The result is the same as path.clone().with_appended(s) but with a single allocation.
Sourcepub fn clone_make_folder(&self) -> FolderPath
pub fn clone_make_folder(&self) -> FolderPath
Clones the path and makes the path a folder.
Returns the path as is if it is already a folder, otherwise appends a file-separator.
Sourcepub fn relative_path(&self) -> &str
pub fn relative_path(&self) -> &str
Gets the relative path (the portion after the base).
Sourcepub fn is_local_path(&self) -> bool
pub fn is_local_path(&self) -> bool
Checks if the path is a local path.
Sourcepub fn is_unix_path(&self) -> bool
pub fn is_unix_path(&self) -> bool
Checks if the path is a Unix path.
Sourcepub fn is_windows_path(&self) -> bool
pub fn is_windows_path(&self) -> bool
Checks if the path is a Windows path.