pub struct StoragePath { /* private fields */ }Expand description
A file or folder path.
§Base Path & Relative Path
Storage paths are divided into a base path and a relative path. The base path is effectively immutable, and the relative path is a sequence of segments divided by file-separators.
Unix Example: Path: /the/path Base Path: / Relative Path: the/path
Windows Example:
Path: C:\The\Path
Base Path: C:
Relative Path: The\Path
URL Example: Path: https://example.com/the/path Base Path: https://example.com/ Relative Path: the/path
§Files & Folders
A storage path can be a file path or a folder path. These are mutually exclusive and
exhaustive. A storage path is a folder path if it is equal to its base path or ends with a
file-separator, otherwise it is a file path. This invariant can be broken with unsafe.
Implementations§
Source§impl StoragePath
Construction
impl StoragePath
Construction
Source§impl StoragePath
Properties
impl StoragePath
Properties
Source§impl StoragePath
Parse
impl StoragePath
Parse
Source§impl StoragePath
Roots
impl StoragePath
Roots
Source§impl StoragePath
To File
impl StoragePath
To File
Source§impl StoragePath
To Folder
impl StoragePath
To Folder
Sourcepub fn to_folder(self) -> Result<FolderPath, Error>
pub fn to_folder(self) -> Result<FolderPath, Error>
Converts the path to a folder path.
Returns Err if the path is not a folder 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.
Source§impl StoragePath
Clone
impl StoragePath
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 StoragePath
Append
impl StoragePath
Append
Sourcepub fn with_appended<S>(self, string: S) -> Self
pub fn with_appended<S>(self, string: S) -> Self
Appends the string.
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.
Source§impl StoragePath
Append Char
impl StoragePath
Append Char
Sourcepub fn append_char(&mut self, c: char)
pub fn append_char(&mut self, c: char)
Appends the char.
Sourcepub fn with_appended_char(self, c: char) -> Self
pub fn with_appended_char(self, c: char) -> Self
Appends the char.
Source§impl StoragePath
Make Folder
impl StoragePath
Make Folder
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 make_folder(self) -> FolderPath
pub fn make_folder(self) -> FolderPath
Makes the storage path a folder.
Returns the path as is if it is already a folder, otherwise appends a file-separator.
Source§impl StoragePath
Truncate
impl StoragePath
Truncate
Source§impl StoragePath
Is-File
impl StoragePath
Is-File
Source§impl StoragePath
Is-Folder
impl StoragePath
Is-Folder
Source§impl StoragePath
Relative Path
impl StoragePath
Relative Path
Sourcepub fn relative_path(&self) -> &str
pub fn relative_path(&self) -> &str
Gets the relative path (the portion after the base).
Source§impl StoragePath
Is Local
impl StoragePath
Is Local
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_local_path_str<S>(path: S) -> bool
pub fn is_local_path_str<S>(path: S) -> bool
Checks if the path is a local path.
Source§impl StoragePath
Is Unix
impl StoragePath
Is Unix
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_unix_path_str<S>(path: S) -> bool
pub fn is_unix_path_str<S>(path: S) -> bool
Checks if the path is a Unix path.
Source§impl StoragePath
Is Windows
impl StoragePath
Is Windows
Sourcepub fn is_windows_path(&self) -> bool
pub fn is_windows_path(&self) -> bool
Checks if the path is a Windows path.
Sourcepub fn is_windows_path_str<S>(path: S) -> bool
pub fn is_windows_path_str<S>(path: S) -> bool
Checks if the path is a Windows path.
Matches drive letter paths (C:\ or C:/) and UNC paths (\\server\...).
Trait Implementations§
Source§impl AsRef<OsStr> for StoragePath
impl AsRef<OsStr> for StoragePath
Source§impl AsRef<Path> for StoragePath
impl AsRef<Path> for StoragePath
Source§impl AsRef<StoragePath> for StoragePath
impl AsRef<StoragePath> for StoragePath
Source§fn as_ref(&self) -> &StoragePath
fn as_ref(&self) -> &StoragePath
Source§impl AsRef<str> for StoragePath
impl AsRef<str> for StoragePath
Source§impl Clone for StoragePath
impl Clone for StoragePath
Source§fn clone(&self) -> StoragePath
fn clone(&self) -> StoragePath
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more