Struct fdir::file::FileInfo

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

Implementations§

source§

impl FileInfo

source

pub fn open(path: impl AsRef<Path>) -> Result<FileInfo>

source

pub fn create(path: impl AsRef<Path>) -> Result<FileInfo>

source

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

source

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

source

pub fn set_extension(&mut self, ext: impl AsRef<OsStr>) -> Result<()>

source

pub fn close(&mut self)

Close the file read-write stream

source

pub fn start_reading(&mut self) -> Result<()>

source

pub fn read(&mut self, len: usize) -> _Result<Vec<u8>>

Reads bytes of the specified length

Examples
use fdir::FileInfo;
use fdir::buffer::Error;

let mut f = FileInfo::create("foo.txt").unwrap();
f.start_writing().unwrap();
f.write("Hello world!").unwrap();

f.start_reading().unwrap();
let hello = f.read(5).unwrap();
assert_eq!(hello.as_slice(), b"Hello");

let world = f.read(6).unwrap();
assert_eq!(world.as_slice(), b" world");

let s = f.read(5).unwrap();
assert_eq!(s.as_slice(), b"!");

let eof = f.read(5);
assert!(eof.is_err());
source

pub fn read_to_end<T: ReadBuf>(&mut self) -> _Result<T>

Read all the remaining bytes and convert it to any type that implements ReadBuf

Examples
use fdir::FileInfo;
use fdir::buffer::Error;

let mut f = FileInfo::create("foo.txt").unwrap();
f.start_writing().unwrap();
f.write("1234567").unwrap();

f.start_reading().unwrap();
f.read(4).unwrap();

let n: i32 = f.read_to_end().unwrap();
assert_eq!(n, 567)
source

pub fn read_line<T: ReadBuf>(&mut self) -> _Result<T>

Read one line and convert it to any type that implements ReadBuf

Examples
use fdir::FileInfo;
use fdir::buffer::Error;

let mut f = FileInfo::create("foo.txt").unwrap();
f.start_writing().unwrap();
f.writeln("Hello").unwrap();
f.writeln("World").unwrap();

f.start_reading().unwrap();
let hello: String = f.read_line().unwrap();
let world: String = f.read_line().unwrap();
assert_eq!(hello.as_str(), "Hello");
assert_eq!(world.as_str(), "World");
source

pub fn read_until<T: ReadBuf>(&mut self, byte: u8) -> _Result<T>

Read all bytes into buf until the delimiter byte or EOF is reached and convert it to any type that implements ReadBuf

Examples
use fdir::FileInfo;
use fdir::buffer::Error;

let mut f = FileInfo::create("foo.txt").unwrap();
f.start_writing().unwrap();
f.write("Hello World !").unwrap();

f.start_reading().unwrap();
let hello: String = f.read_until(b' ').unwrap();
let world: String = f.read_until(b' ').unwrap();
let s: String = f.read_until(b' ').unwrap();
assert_eq!(hello.as_str(), "Hello");
assert_eq!(world.as_str(), "World");
assert_eq!(s.as_str(), "!")
source

pub fn truncate(&mut self) -> Result<()>

It will truncate the file to 0 length

source

pub fn start_writing(&mut self) -> Result<()>

source

pub fn write<T: AsRef<[u8]>>(&mut self, buf: T) -> _Result<()>

source

pub fn writeln<T: AsRef<[u8]>>(&mut self, buf: T) -> _Result<()>

source

pub fn write_end_with<T: AsRef<[u8]>>(&mut self, buf: T, end: u8) -> _Result<()>

Trait Implementations§

source§

impl Clone for FileInfo

source§

fn clone(&self) -> Self

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 FileInfo

source§

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

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

impl Display for FileInfo

source§

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

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

impl FileAttr for FileInfo

source§

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

Ignore the file name and check that all bytes are equal

If both files have a length of 0, the return is always true.

source§

fn as_path(&self) -> &Path

source§

fn size(&self) -> u64

source§

fn rename<T: AsRef<OsStr>>(&mut self, name: T) -> Result<()>

Rename a file or directory Read more
source§

fn copy_new<P: AsRef<Path>>(&self, path: P) -> RecoverResult<'_>

Copy a file or directory to a new destination path Read more
source§

fn move_new<P: AsRef<Path>>(&mut self, path: P) -> RecoverResult<'_>

Move a file or directory to a new destination path Read more
source§

fn file_name(&self) -> Option<&OsStr>

Returns None if the path is root directory
source§

fn metadata(&self) -> Result<Metadata>

source§

fn parent(&self) -> Option<DirectoryInfo>

Return None if the path is a root directory
source§

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

source§

fn set_permissions(&self, perm: Permissions) -> Result<()>

source§

fn read_only(&self) -> Result<bool>

source§

fn set_readonly(&self, readonly: bool) -> Result<()>

source§

fn delete(self) -> Result<()>

source§

fn copy_to<P: AsRef<Path>>(&self, path: P) -> RecoverResult<'_>

Copy a file or directory to a new directory Read more
source§

fn move_to<P: AsRef<Path>>(&mut self, path: P) -> RecoverResult<'_>

Move a file or directory to a new directory Read more
source§

impl From<File> for FileInfo

source§

fn from(value: File) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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.