Struct simple_fs::SFile

source ·
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 guarantees the SFile contract describe in the struct

source

pub fn new(path: impl Into<PathBuf>) -> Result<Self>

Constructor for SFile accepting anything that implements Into.

Note: This is quite ergonomic and allows for avoiding a PathBuf allocation if a PathBuf is provided.

source

pub fn from_path(path: impl AsRef<Path>) -> Result<Self>

Constructor from File and all impl AsRef.

Returns Result

Note: Prefer the use of the SPath::try_from(…) when available as it might avoid a PathBuf allocation.

source

pub fn from_path_ok(path: impl AsRef<Path>) -> Option<Self>

Constructor for anything that impl AsRef.

Returns Option. Useful for filter_map.

Note: Favor using concrete type functions like SPath::from_path_buf_ok when available.

source

pub fn from_path_buf_ok(path_buf: PathBuf) -> Option<Self>

Constructor from PathBuf returning an Option, none if validation fail. Useful for filter_map.

source

pub fn from_fs_entry_ok(fs_entry: DirEntry) -> Option<Self>

Constructor from fs::DirEntry returning an Option, none if validation fail. Useful for filter_map.

source

pub fn from_walkdir_entry_ok(wd_entry: DirEntry) -> Option<Self>

Constructor from walkdir::DirEntry returning an Option, none if validation fail. Useful for filter_map.

source§

impl SFile

Public return Path constructs.

source

pub fn into_path_buf(self) -> PathBuf

source

pub fn path(&self) -> &Path

source§

impl SFile

Public file components as str methods.

source

pub fn to_str(&self) -> &str

Returns the &str of the path.

NOTE: We know that this must be Some() since the SFile constructor guarantees that the path.to_str() is valid.

source

pub fn file_name(&self) -> &str

Returns the &str representation of the file_name()

NOTE: According to the constructors’ contract, this method will never return “” as a file_name() is required for construction.

source

pub fn file_stem(&self) -> &str

Returns the &str representation of the file_stem()

NOTE: According to the constructors’ contract, this method will never return “” as a file_name() is required for construction, and stem is always part of it.

source

pub fn stem(&self) -> &str

👎Deprecated: use file_stem(..)
source

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.

source

pub fn ext(&self) -> &str

Same as .extension() but returns “” if no extension

source

pub fn modified(&self) -> Result<SystemTime>

Returns the path.metadata modified as SystemTime.

source

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.

source

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.

source

pub fn parent(&self) -> Option<SPath>

Trait Implementations§

source§

impl AsRef<Path> for SFile

source§

fn as_ref(&self) -> &Path

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Debug for SFile

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for SFile

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&SFile> for String

source§

fn from(val: &SFile) -> Self

Converts to this type from the input type.
source§

impl From<SFile> for String

source§

fn from(val: SFile) -> Self

Converts to this type from the input type.
source§

impl TryFrom<&String> for SFile

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(path: &String) -> Result<SFile>

Performs the conversion.
source§

impl TryFrom<&str> for SFile

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(path: &str) -> Result<SFile>

Performs the conversion.
source§

impl TryFrom<DirEntry> for SFile

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(fs_entry: DirEntry) -> Result<SFile>

Performs the conversion.
source§

impl TryFrom<DirEntry> for SFile

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(wd_entry: DirEntry) -> Result<SFile>

Performs the conversion.
source§

impl TryFrom<PathBuf> for SFile

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(path_buf: PathBuf) -> Result<SFile>

Performs the conversion.
source§

impl TryFrom<SPath> for SFile

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(spath: SPath) -> Result<SFile>

Performs the conversion.
source§

impl TryFrom<String> for SFile

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(path: String) -> Result<SFile>

Performs the conversion.

Auto Trait Implementations§

§

impl RefUnwindSafe for SFile

§

impl Send for SFile

§

impl Sync for SFile

§

impl Unpin for SFile

§

impl UnwindSafe for SFile

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.