pub struct SPath { /* private fields */ }Expand description
An SPath can be constructed from a Path, io::DirEntry, or walkdir::DirEntry and guarantees the following:
- The full path is UTF-8 valid.
- It does NOT have to have a file NAME (.e.g, ‘./’). If no file_name, .file_name() will return “”
Implementations§
Source§impl SPath
impl SPath
Constructors that guarantee the SPath contract described in the struct
Sourcepub fn new(path: impl Into<PathBuf>) -> Result<Self>
pub fn new(path: impl Into<PathBuf>) -> Result<Self>
Constructor for SPath accepting anything that implements Into
Note: This is quite ergonomic and allows for avoiding a PathBuf allocation if a PathBuf is provided.
Sourcepub fn from_path(path: impl AsRef<Path>) -> Result<Self>
pub fn from_path(path: impl AsRef<Path>) -> Result<Self>
Constructor from Path and all impl AsRef
Returns Result
Note: Prefer the use of the SPath::try_from(…) or new when available as it might avoid a PathBuf allocation.
Sourcepub fn from_path_ok(path: impl AsRef<Path>) -> Option<Self>
pub fn from_path_ok(path: impl AsRef<Path>) -> Option<Self>
Constructor for anything that implements AsRef
Returns Option
Note: Favor using concrete type functions like SPath::from_path_buf_ok
when available.
Sourcepub fn from_path_buf_ok(path_buf: PathBuf) -> Option<Self>
pub fn from_path_buf_ok(path_buf: PathBuf) -> Option<Self>
Constructed from PathBuf returns 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 SPath
impl SPath
Public getters
Sourcepub fn to_str(&self) -> &str
pub fn to_str(&self) -> &str
Returns the &str of the path.
NOTE: We know that this must be Some() since the SPath constructor guarantees that the path.to_str() is valid.
Sourcepub fn file_name(&self) -> Option<&str>
pub fn file_name(&self) -> Option<&str>
Returns the Option<&str> representation of the path.file_name()
Note: if the OsStr cannot be made into utf8 will be None
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the &str representation of the path.file_name()
Note: If no file name (e.g., ./) or OsStr no utf8, will be empty string
Sourcepub fn file_stem(&self) -> Option<&str>
pub fn file_stem(&self) -> Option<&str>
Returns the Option<&str> representation of the file_stem()
Note: if the OsStr cannot be made into utf8 will be None
Sourcepub fn stem(&self) -> &str
pub fn stem(&self) -> &str
Returns the &str representation of the file_name()
Note: If no file name (e.g., ./) or OsStr no utf8, will be 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 SPath construction.
Sourcepub fn modified(&self) -> Result<SystemTime>
pub fn modified(&self) -> Result<SystemTime>
Returns the path.metadata modified.
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 292277-01-09 04:00:54 UTC.
Thus, for all intents and purposes, it is far enough to not worry.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SPath
impl RefUnwindSafe for SPath
impl Send for SPath
impl Sync for SPath
impl Unpin for SPath
impl UnwindSafe for SPath
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)