Skip to main content

FileTool

Struct FileTool 

Source
pub struct FileTool;
Expand description

File utility wrapper

Implementations§

Source§

impl FileTool

Source

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

Read the entire contents of a file into a string

Source

pub fn read_bytes<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>>

Read the entire contents of a file into a bytes vector

Source

pub fn write_string<P: AsRef<Path>, C: AsRef<[u8]>>( &self, path: P, content: C, ) -> Result<()>

Write a string to a file (creates or overwrites)

Source

pub fn exists<P: AsRef<Path>>(&self, path: P) -> bool

Check if a path exists

Source

pub fn is_file<P: AsRef<Path>>(&self, path: P) -> bool

Check if a path is a file

Source

pub fn is_dir<P: AsRef<Path>>(&self, path: P) -> bool

Check if a path is a directory

Source

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

Create a single directory (fails if parent doesn’t exist)

Source

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

Recursively create a directory and all of its parent components if they are missing

Source

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

Delete a file

Source

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

Delete an empty directory

Source

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

Recursively delete a directory and all of its contents

Source

pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>( &self, from: P, to: Q, ) -> Result<u64>

Copy a file

Source

pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>( &self, from: P, to: Q, ) -> Result<()>

Rename or move a file/directory

Source

pub fn list_files<P: AsRef<Path>>(&self, dir: P) -> Result<Vec<PathBuf>>

List only files in a directory (non-recursive)

Source

pub fn list_dirs<P: AsRef<Path>>(&self, dir: P) -> Result<Vec<PathBuf>>

List only directories in a directory (non-recursive)

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,