pub struct SFile { /* private fields */ }
Expand description
An SFile can be constructed from a Path, io::DirEntry, or walkdir::DirEntry and guarantees the following:
- The entry is a file (exists).
- It has a file name.
- The full path is UTF-8 valid.
Implementations§
Source§impl SFile
Constructors that guarantee the SFile contract described in the struct
impl SFile
Constructors that guarantee the SFile contract described in the struct
Sourcepub fn new(path: impl Into<Utf8PathBuf>) -> Result<Self>
pub fn new(path: impl Into<Utf8PathBuf>) -> Result<Self>
Constructor for SFile accepting anything that implements Into
Sourcepub fn from_std_path_buf(path_buf: PathBuf) -> Result<Self>
pub fn from_std_path_buf(path_buf: PathBuf) -> Result<Self>
Constructor from standard PathBuf.
Sourcepub fn from_std_path(path: impl AsRef<Path>) -> Result<Self>
pub fn from_std_path(path: impl AsRef<Path>) -> Result<Self>
Constructor from standard Path and all impl AsRef
Sourcepub fn from_walkdir_entry(wd_entry: DirEntry) -> Result<Self>
pub fn from_walkdir_entry(wd_entry: DirEntry) -> Result<Self>
Constructor from walkdir::DirEntry
Sourcepub fn from_std_path_ok(path: impl AsRef<Path>) -> Option<Self>
pub fn from_std_path_ok(path: impl AsRef<Path>) -> Option<Self>
Constructors for anything that implements AsRef
Returns Option
Sourcepub fn from_std_path_buf_ok(path_buf: PathBuf) -> Option<Self>
pub fn from_std_path_buf_ok(path_buf: PathBuf) -> Option<Self>
Constructor from PathBuf returning an Option, none if validation fails. Useful for filter_map.
Sourcepub fn from_fs_entry_ok(fs_entry: DirEntry) -> Option<Self>
pub fn from_fs_entry_ok(fs_entry: DirEntry) -> Option<Self>
Constructor from fs::DirEntry returning an Option; none if validation fails. Useful for filter_map.
Sourcepub fn from_walkdir_entry_ok(wd_entry: DirEntry) -> Option<Self>
pub fn from_walkdir_entry_ok(wd_entry: DirEntry) -> Option<Self>
Constructor from walkdir::DirEntry returning an Option; none if validation fails. Useful for filter_map.
Source§impl SFile
Public getters
impl SFile
Public getters
Sourcepub fn to_str(&self) -> &str
👎Deprecated: Use as_str()
instead
pub fn to_str(&self) -> &str
as_str()
insteadReturns the &str of the path.
NOTE: We know that this must be Some() since the SFile constructor guarantees that the path.as_str() is valid.
pub fn as_str(&self) -> &str
Sourcepub fn file_name(&self) -> Option<&str>
pub fn file_name(&self) -> Option<&str>
Returns the Option<&str> representation of the path.file_name()
.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the &str representation of the path.file_name()
.
Note: If no file name will be an empty string
Sourcepub fn parent_name(&self) -> &str
pub fn parent_name(&self) -> &str
Returns the parent name, and empty static &str if no present
Sourcepub fn file_stem(&self) -> Option<&str>
pub fn file_stem(&self) -> Option<&str>
Returns the Option<&str> representation of the file_stem().
Sourcepub fn stem(&self) -> &str
pub fn stem(&self) -> &str
Returns the &str representation of the file_name()
.
Note: If no stem, will be an empty string
Sourcepub fn extension(&self) -> Option<&str>
pub fn extension(&self) -> Option<&str>
Returns the Option<&str> representation of the extension().
NOTE: This should never be a non-UTF-8 string as the path was validated during SFile construction.
Sourcepub fn modified(&self) -> Result<SystemTime>
pub fn modified(&self) -> Result<SystemTime>
Returns the path.metadata modified as SystemTime.
Sourcepub fn modified_us(&self) -> Result<i64>
pub fn modified_us(&self) -> Result<i64>
Returns the epoch duration in microseconds.
Note: The maximum UTC date would be approximately 2262-04-11
.
Thus, for all intents and purposes, it is far enough not to worry.
Sourcepub fn file_size(&self) -> Result<i64>
pub fn file_size(&self) -> Result<i64>
Returns the file size in bytes as i64
.
Note: In the highly unlikely event that the size exceeds i64::MAX
,
i64::MAX
is returned. i64::MAX
represents 8,388,607 terabytes,
providing ample margin before it becomes a concern.
Sourcepub fn is_absolute(&self) -> bool
pub fn is_absolute(&self) -> bool
Returns true if the internal path is absolute.
Sourcepub fn is_relative(&self) -> bool
pub fn is_relative(&self) -> bool
Returns true if the internal path is relative.
Source§impl SFile
Transformers
impl SFile
Transformers
pub fn canonicalize(&self) -> Result<SFile>
Sourcepub fn collapse(&self) -> SFile
pub fn collapse(&self) -> SFile
Collapse a path without performing I/O.
All redundant separator and up-level references are collapsed.
However, this does not resolve links.
Sourcepub fn into_collapsed(self) -> SFile
pub fn into_collapsed(self) -> SFile
Same as [collapse
] but consume and create a new SPath only if needed
Sourcepub fn is_collapsed(&self) -> bool
pub fn is_collapsed(&self) -> bool
Return true
if the path is collapsed.
§Quirk
If the path does not start with ./
but contains ./
in the middle,
then this function might returns true
.
Sourcepub fn join(&self, leaf_path: impl Into<Utf8PathBuf>) -> SPath
pub fn join(&self, leaf_path: impl Into<Utf8PathBuf>) -> SPath
Joins the current path with the specified leaf_path.
This method creates a new path by joining the existing path with a specified leaf_path and returns the result as an SPath.
Sourcepub fn join_std_path(&self, leaf_path: impl AsRef<Path>) -> Result<SPath>
pub fn join_std_path(&self, leaf_path: impl AsRef<Path>) -> Result<SPath>
Joins a standard Path to the path of this SFile.
Sourcepub fn new_sibling(&self, leaf_path: &str) -> SPath
pub fn new_sibling(&self, leaf_path: &str) -> SPath
Creates a new sibling path with the specified leaf_path.
Generates a new path in the same parent directory as the current file, appending the leaf_path.
Sourcepub fn new_sibling_std_path(&self, leaf_path: impl AsRef<Path>) -> Result<SPath>
pub fn new_sibling_std_path(&self, leaf_path: impl AsRef<Path>) -> Result<SPath>
Creates a new sibling path with the specified standard path.