Struct filey::Filey

source ·
pub struct Filey { /* private fields */ }

Implementations§

source§

impl Filey

source

pub fn new<P: AsRef<Path>>(path: P) -> Self

Constructs a new Filey.

source

pub fn path(&self) -> &PathBuf

Returns path to the file.

source

pub fn file_type(&self) -> Option<FileTypes>

Returns the type of the file. If the path doesn’t exist, return None.

source

pub fn size(&self) -> Result<u64>

Returns size of the file.

§Errors
  • The user lacks permissions.
  • The file doesn’t exist.
§Examples
let size = Filey::new("install.sh").size()?;
println!("{}", size); // 1079
source

pub fn permissions(&self) -> Result<Permissions>

source

pub fn file_name(&self) -> Option<String>

Returns the file name or the directory name. Returns None if the path terminates in …

§Examples
let file = Filey::new("src/lib.rs");
assert_eq!(file.file_name()?.as_str(), "lib.rs");

let directory = Filey::new("src/lib.rs");
assert_eq!(directory.file_name()?.as_str(), "src");
source

pub fn file_stem(&self) -> Option<String>

Returns the stem portion of the file name. Returns None if there is no file name.

§Examples
let file = Filey::new("src/lib.rs");
assert_eq!(file.file_stem()?.as_str(), "lib");
source

pub fn parent_dir(&self) -> Option<String>

Returns the parent directory. Returns None if the path terminates in a root or prefix, or if it’s the empty string.

§Examples
let file = Filey::new("src/lib.rs");
assert_eq!(file.parent_dir()?.as_str(), "src");
source

pub fn absolutize(&mut self) -> Result<&mut Self>

Returns the absolutized path of the file or the directory.

§Errors
  • The environment variable HOME isn’t set.
  • The environment variable’s name contains the equal sign character (=) or the NUL character.
  • The environment variable’s value is not valid Unicode.
§Examples
let mut file = Filey::new("src/lib.rs");
assert_eq!(file.absolutized()?
    .to_string()
    .as_str(),
    "/home/Tom/src/lib.rs");
source

pub fn canonicalized(&mut self) -> Result<&mut Self>

Return the canonicalized(absolutized and symbolic links solved) path.

§Errors
  • The path doesn’t exist.
  • A non-final component in path is not a directory.
§Examples
// nvim/init.lua -> /home/Lisa/dotfiles/nvim/init.lua
let mut file = Filey::new("nvim/init.lua");
assert_eq!(file.canonicalized()?
    .to_string()
    .as_str(),
    "/home/Lisa/dotfiles/nvim/init.lua");
source

pub fn expand_user(&mut self) -> Result<&mut Self>

Replaces an initial tilde of the path by the environment variable HOME.

§Errors
  • The environment variable HOME isn’t set.
  • The environment variable’s name contains the equal sign character (=) or the NUL character.
  • The environment variable’s value is not valid Unicode.
§Examples
let mut directory = Filey::new("~/audio");
assert_eq!(directory.expand_user()?
    .to_string()
    .as_str(),
    "/home/Mike/audio");
source

pub fn contract_user(&mut self) -> Result<&mut Self>

Replaces path_to_home by tilde.

§Errors
  • The environment variable HOME isn’t set.
  • The environment variable’s name contains the equal sign character (=) or the NUL character.
  • The environment variable’s value is not valid Unicode.
§Examples
let mut file = Filey::new("/home/Meg/cats.png");
assert_eq!(file.close_user()?.as_str(), "~/cats.png")
source

pub fn move_to<P: AsRef<Path>>(&mut self, path: P) -> Result<&mut Self>

Move a file or a directory to the given path.

§Errors
  • The user lacks permissions.
  • from(Filey) and to(path: P) are on separate filesystems.
§Panics
  • Both from and to don’t exist.
§Examples
let mut file = Filey::new("cats.png");
file.move_to("photos/animals/")?;
assert_eq!(Path::new("photos/animals/cats.png").exists(), true);
source

pub fn remove(&self) -> Result<()>

Detects the type of a file and remove the file.

§Errors
  • The file doesn’t exist.
  • The user lacks permissions.
§Examples
let file = Filey::new("coredump");
file.remove()?;
assert_eq!(file.exists(), false);
source

pub fn create(&self, file_type: FileTypes) -> Result<&Self>

Create a new file or directory.

§Examples
let directory = File::new("photo/dogs").create(FileTypes::Directory)?;
assert_eq!(directory.exists(), true);
source

pub fn copy<P: AsRef<Path>>(&self, path: P) -> Result<Self>

Copy the contents of file to another.

(Unix only) Create a new symbolic link on the filesystem.

§Examples
let mut vimrc_dotfiles = Filey::new("~/dotfiles/vimrc");
vimrc_dotfiles.create(FileTypes::File).symlink("~/.vimrc")?;
assert!(Path::new("~/.vimrc").exists());

Create a new hard link on the filesystem.

§Errors

The original path is not a file or doesn’t exist.

§Examples
let mut file = Filey::new("foo.txt");
file.create(FileTypes::File).hard_link("bar.txt")?;
assert_eq!(Path::new("bar.txt").exists(), true);
source

pub fn exists(&self) -> bool

source

pub fn is_file(&self) -> bool

source

pub fn is_dir(&self) -> bool

Trait Implementations§

source§

impl AsRef<Path> for Filey

source§

fn as_ref(&self) -> &Path

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

impl Clone for Filey

source§

fn clone(&self) -> Filey

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Filey

source§

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

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

impl<'de> Deserialize<'de> for Filey

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Filey

source§

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

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

impl Hash for Filey

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Filey

source§

fn cmp(&self, other: &Filey) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Filey

source§

fn eq(&self, other: &Filey) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Filey

source§

fn partial_cmp(&self, other: &Filey) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Filey

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Filey

source§

impl StructuralPartialEq for Filey

Auto Trait Implementations§

§

impl RefUnwindSafe for Filey

§

impl Send for Filey

§

impl Sync for Filey

§

impl Unpin for Filey

§

impl UnwindSafe for Filey

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,