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
Write With Headers
impl FilePath
Write With Headers
Sourcepub fn write_with_headers<D>(
&self,
data: D,
headers: &Headers,
) -> Result<(), Error>
pub fn write_with_headers<D>( &self, data: D, headers: &Headers, ) -> Result<(), Error>
Writes the data to the file with the given headers, overwriting it if it already exists.
Headers (e.g. Content-Type) are applied by backends that support object metadata, such as
Cloudflare R2. The local filesystem backend ignores them.
Sourcepub fn write_with_headers_if_not_exists<D>(
&self,
data: D,
headers: &Headers,
) -> Result<bool, Error>
pub fn write_with_headers_if_not_exists<D>( &self, data: D, headers: &Headers, ) -> Result<bool, Error>
Writes the data to the file with the given headers if the file does not already exist.
Headers (e.g. Content-Type) are applied by backends that support object metadata, such as
Cloudflare R2. The local filesystem backend ignores them.
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.
Trait Implementations§
Source§impl Deref for FilePath
impl Deref for FilePath
Source§type Target = StoragePath
type Target = StoragePath
Source§fn deref(&self) -> &StoragePath
fn deref(&self) -> &StoragePath
impl Eq for FilePath
Source§impl From<FilePath> for StoragePath
impl From<FilePath> for StoragePath
Source§impl Ord for FilePath
impl Ord for FilePath
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for FilePath
impl PartialOrd for FilePath
impl StructuralPartialEq for FilePath
Auto Trait Implementations§
impl Freeze for FilePath
impl RefUnwindSafe for FilePath
impl Send for FilePath
impl Sync for FilePath
impl Unpin for FilePath
impl UnsafeUnpin for FilePath
impl UnwindSafe for FilePath
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more