pub struct Filey { /* private fields */ }Implementations§
source§impl Filey
impl Filey
sourcepub fn file_type(&self) -> Option<FileTypes>
pub fn file_type(&self) -> Option<FileTypes>
Returns the type of the file. If the path doesn’t exist, return None.
pub fn permissions(&self) -> Result<Permissions>
sourcepub fn file_name(&self) -> Option<String>
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");sourcepub fn file_stem(&self) -> Option<String>
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");sourcepub fn parent_dir(&self) -> Option<String>
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");sourcepub fn absolutize(&mut self) -> Result<&mut Self>
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");sourcepub fn canonicalized(&mut self) -> Result<&mut Self>
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");sourcepub fn expand_user(&mut self) -> Result<&mut Self>
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");sourcepub fn contract_user(&mut self) -> Result<&mut Self>
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")sourcepub fn move_to<P: AsRef<Path>>(&mut self, path: P) -> Result<&mut Self>
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);sourcepub fn create(&self, file_type: FileTypes) -> Result<&Self>
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);sourcepub fn copy<P: AsRef<Path>>(&self, path: P) -> Result<Self>
pub fn copy<P: AsRef<Path>>(&self, path: P) -> Result<Self>
Copy the contents of file to another.
sourcepub fn symlink<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
pub fn symlink<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
(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());pub fn exists(&self) -> bool
pub fn is_file(&self) -> bool
pub fn is_dir(&self) -> bool
pub fn is_symlink(&self) -> bool
Trait Implementations§
source§impl<'de> Deserialize<'de> for Filey
impl<'de> Deserialize<'de> for Filey
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 Ord for Filey
impl Ord for Filey
source§impl PartialEq for Filey
impl PartialEq for Filey
source§impl PartialOrd for Filey
impl PartialOrd for Filey
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moreimpl Eq for Filey
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> 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
Mutably borrows from an owned value. Read more