File

Struct File 

Source
pub struct File<'a> { /* private fields */ }
Expand description

Struct to represent a file or directory. This struct is used to abstract away the underlying file system.

Implementations§

Source§

impl File<'_>

Source

pub fn new(path_str: &str) -> File<'_>

Create a new file.

Source

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

Return the file extension.

Source

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

Return the file name.

Source

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

Return the file stem.

Source

pub fn is_dir(&self) -> bool

Check if the file is a directory.

Source

pub fn is_file(&self) -> bool

Check if the file is a file.

Source

pub fn exist(&self) -> bool

Check if the file exist.

Source

pub fn read_dir(&self) -> Result<Vec<String>, FileErr>

If File is a directory, return a vector of the files in the directory. If File is a file, return an error FileErr::NotADirectory.

Source

pub fn create_file(&self) -> Result<(), FileErr>

Create a file. If the file already exist, an error FileErr::FileAlreadyExist will be returned.

Source

pub fn rename(&self, new_name: &str) -> Result<(), FileErr>

Rename file or directory.

Source

pub fn path(&self) -> String

Auto Trait Implementations§

§

impl<'a> Freeze for File<'a>

§

impl<'a> RefUnwindSafe for File<'a>

§

impl<'a> Send for File<'a>

§

impl<'a> Sync for File<'a>

§

impl<'a> Unpin for File<'a>

§

impl<'a> UnwindSafe for File<'a>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.