pub struct FileInfo { /* private fields */ }Implementations§
source§impl FileInfo
impl FileInfo
pub fn open(path: impl AsRef<Path>) -> Result<FileInfo>
pub fn create(path: impl AsRef<Path>) -> Result<FileInfo>
pub fn start_reading(&mut self) -> Result<()>
sourcepub fn read(&mut self, len: usize) -> _Result<Vec<u8>>
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());sourcepub fn read_to_end<T: ReadBuf>(&mut self) -> _Result<T>
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)sourcepub fn read_line<T: ReadBuf>(&mut self) -> _Result<T>
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");
sourcepub fn read_until<T: ReadBuf>(&mut self, byte: u8) -> _Result<T>
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(), "!")pub fn start_writing(&mut self) -> Result<()>
pub fn write<T: AsRef<[u8]>>(&mut self, buf: T) -> _Result<()>
pub fn writeln<T: AsRef<[u8]>>(&mut self, buf: T) -> _Result<()>
pub fn write_end_with<T: AsRef<[u8]>>(&mut self, buf: T, end: u8) -> _Result<()>
Trait Implementations§
source§impl FileAttr for FileInfo
impl FileAttr for FileInfo
source§fn eq(&self, other: &Self) -> bool
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.
fn as_path(&self) -> &Path
fn size(&self) -> u64
source§fn rename<T: AsRef<OsStr>>(&mut self, name: T) -> Result<()>
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<'_>
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<'_>
fn move_new<P: AsRef<Path>>(&mut self, path: P) -> RecoverResult<'_>
Move a file or directory to a new destination path Read more
fn metadata(&self) -> Result<Metadata>
source§fn parent(&self) -> Option<DirectoryInfo>
fn parent(&self) -> Option<DirectoryInfo>
Return None if the path is a root directory
fn permissions(&self) -> Result<Permissions>
fn set_permissions(&self, perm: Permissions) -> Result<()>
fn read_only(&self) -> Result<bool>
fn set_readonly(&self, readonly: bool) -> Result<()>
fn delete(self) -> Result<()>
Auto Trait Implementations§
impl RefUnwindSafe for FileInfo
impl Send for FileInfo
impl Sync for FileInfo
impl Unpin for FileInfo
impl UnwindSafe for FileInfo
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