Struct path_abs::FileEdit [−][src]
A read/write file handle with path()
attached and improved error messages. Contains methods
and trait implements for both readable and writeable files.
Examples
use std::io::{Read, Seek, Write, SeekFrom}; use path_abs::FileEdit; let example = "example.txt"; let expected = "foo\nbar"; let mut edit = FileEdit::create(example)?; let mut s = String::new(); edit.write_all(expected.as_bytes())?; edit.seek(SeekFrom::Start(0))?; edit.read_to_string(&mut s)?; assert_eq!(expected, s);
Implementations
impl FileEdit
[src]
pub fn open<P: AsRef<Path>>(path: P, options: OpenOptions) -> Result<FileEdit>
[src]
Open the file with the given OpenOptions
but always sets read
and write
to true.
pub fn create<P: AsRef<Path>>(path: P) -> Result<FileEdit>
[src]
Open the file in editing mode, truncating it first if it exists and creating it otherwise.
pub fn append<P: AsRef<Path>>(path: P) -> Result<FileEdit>
[src]
Open the file for appending, creating it if it doesn't exist.
pub fn edit<P: AsRef<Path>>(path: P) -> Result<FileEdit>
[src]
Open the file for editing (reading and writing) but do not create it if it doesn't exist.
pub fn sync_all(&self) -> Result<()>
[src]
Attempts to sync all OS-internal metadata to disk.
This function will attempt to ensure that all in-core data reaches the filesystem before returning.
This function is identical to std::fs::File::sync_all except it has error messages which include the action and the path.
pub fn sync_data(&self) -> Result<()>
[src]
This function is similar to sync_all, except that it may not synchronize file metadata to the filesystem.
This function is identical to std::fs::File::sync_data except it has error messages which include the action and the path.
pub fn set_len(&mut self, size: u64) -> Result<()>
[src]
Truncates or extends the underlying file, updating the size of this file to become size.
This function is identical to std::fs::File::set_len except:
- It has error messages which include the action and the path.
- It takes
&mut self
instead of&self
.
pub fn set_permissions(&mut self, perm: Permissions) -> Result<()>
[src]
Changes the permissions on the underlying file.
This function is identical to std::fs::File::set_permissions except:
- It has error messages which include the action and the path.
- It takes
&mut self
instead of&self
.
pub fn read_string(&mut self) -> Result<String>
[src]
Read what remains of the file to a String
.
pub fn write_str(&mut self, s: &str) -> Result<()>
[src]
Shortcut to self.write_all(s.as_bytes())
with slightly
improved error message.
pub fn flush(&mut self) -> Result<()>
[src]
std::io::File::flush
buth with the new error type.
Trait Implementations
impl AsRef<File> for FileEdit
[src]
impl AsRef<FileOpen> for FileEdit
[src]
impl Borrow<File> for FileEdit
[src]
impl<'a> Borrow<File> for &'a FileEdit
[src]
impl Borrow<FileOpen> for FileEdit
[src]
impl<'a> Borrow<FileOpen> for &'a FileEdit
[src]
impl Debug for FileEdit
[src]
impl From<FileEdit> for FileOpen
[src]
impl Read for FileEdit
[src]
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
[src]
pub fn read_vectored(
&mut self,
bufs: &mut [IoSliceMut<'_>]
) -> Result<usize, Error>
1.36.0[src]
&mut self,
bufs: &mut [IoSliceMut<'_>]
) -> Result<usize, Error>
pub fn is_read_vectored(&self) -> bool
[src]
pub unsafe fn initializer(&self) -> Initializer
[src]
pub fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
1.0.0[src]
pub fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
pub fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
pub fn by_ref(&mut self) -> &mut Self
1.0.0[src]
pub fn bytes(self) -> Bytes<Self>
1.0.0[src]
pub fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
pub fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
impl Seek for FileEdit
[src]
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
[src]
pub fn stream_len(&mut self) -> Result<u64, Error>
[src]
pub fn stream_position(&mut self) -> Result<u64, Error>
1.51.0[src]
impl Write for FileEdit
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
[src]
fn flush(&mut self) -> Result<()>
[src]
pub fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>
1.36.0[src]
pub fn is_write_vectored(&self) -> bool
[src]
pub fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0[src]
pub fn write_all_vectored(
&mut self,
bufs: &mut [IoSlice<'_>]
) -> Result<(), Error>
[src]
&mut self,
bufs: &mut [IoSlice<'_>]
) -> Result<(), Error>
pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>
1.0.0[src]
pub fn by_ref(&mut self) -> &mut Self
1.0.0[src]
Auto Trait Implementations
impl RefUnwindSafe for FileEdit
impl Send for FileEdit
impl Sync for FileEdit
impl Unpin for FileEdit
impl UnwindSafe for FileEdit
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,