pub struct FileWrite(_);
Expand description
A write-only file handle with path()
attached and improved error messages. Contains only the
methods and trait implementations which are allowed by a write-only file.
Examples
use std::io::Write;
use path_abs::{PathFile, FileWrite};
let example = "example.txt";
let expected = "foo\nbar";
let mut write = FileWrite::create(example)?;
write.write_all(expected.as_bytes())?;
write.flush();
let file = PathFile::new(example)?;
assert_eq!(expected, file.read_string()?);
Implementations§
source§impl FileWrite
impl FileWrite
sourcepub fn open<P: AsRef<Path>>(path: P, options: OpenOptions) -> Result<FileWrite>
pub fn open<P: AsRef<Path>>(path: P, options: OpenOptions) -> Result<FileWrite>
Open the file with the given OpenOptions
but always sets write
to true.
sourcepub fn create<P: AsRef<Path>>(path: P) -> Result<FileWrite>
pub fn create<P: AsRef<Path>>(path: P) -> Result<FileWrite>
Open the file in write-only mode, truncating it first if it exists and creating it otherwise.
sourcepub fn open_append<P: AsRef<Path>>(path: P) -> Result<FileWrite>
pub fn open_append<P: AsRef<Path>>(path: P) -> Result<FileWrite>
Open the file for appending, creating it if it doesn’t exist.
sourcepub fn open_edit<P: AsRef<Path>>(path: P) -> Result<FileWrite>
pub fn open_edit<P: AsRef<Path>>(path: P) -> Result<FileWrite>
Open the file for editing (reading and writing) but do not create it if it doesn’t exist.
pub fn path(&self) -> &PathFile
sourcepub fn sync_all(&self) -> Result<()>
pub fn sync_all(&self) -> Result<()>
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.
sourcepub fn sync_data(&self) -> Result<()>
pub fn sync_data(&self) -> Result<()>
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.
sourcepub fn set_len(&mut self, size: u64) -> Result<()>
pub fn set_len(&mut self, size: u64) -> Result<()>
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
.
sourcepub fn set_permissions(&mut self, perm: Permissions) -> Result<()>
pub fn set_permissions(&mut self, perm: Permissions) -> Result<()>
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
.
Trait Implementations§
source§impl Seek for FileWrite
impl Seek for FileWrite
source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
source§impl Write for FileWrite
impl Write for FileWrite
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)