pub struct FileWrite(/* private fields */);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>(path: P, options: OpenOptions) -> Result<FileWrite, Error>
pub fn open<P>(path: P, options: OpenOptions) -> Result<FileWrite, Error>
Open the file with the given OpenOptions but always sets write to true.
Sourcepub fn create<P>(path: P) -> Result<FileWrite, Error>
pub fn create<P>(path: P) -> Result<FileWrite, Error>
Open the file in write-only mode, truncating it first if it exists and creating it otherwise.
Sourcepub fn append<P>(path: P) -> Result<FileWrite, Error>
pub fn append<P>(path: P) -> Result<FileWrite, Error>
Open the file for appending, creating it if it doesn’t exist.
Sourcepub fn edit<P>(path: P) -> Result<FileWrite, Error>
pub fn edit<P>(path: P) -> Result<FileWrite, Error>
Open the file for editing (reading and writing) but do not create it if it doesn’t exist.
Sourcepub fn sync_all(&self) -> Result<(), Error>
pub fn sync_all(&self) -> Result<(), Error>
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<(), Error>
pub fn sync_data(&self) -> Result<(), Error>
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<(), Error>
pub fn set_len(&mut self, size: u64) -> Result<(), Error>
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 selfinstead of&self.
Sourcepub fn set_permissions(&mut self, perm: Permissions) -> Result<(), Error>
pub fn set_permissions(&mut self, perm: Permissions) -> Result<(), Error>
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 selfinstead of&self.
Methods from Deref<Target = FileOpen>§
Trait Implementations§
Source§impl Seek for FileWrite
impl Seek for FileWrite
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)Source§impl Write for FileWrite
impl Write for FileWrite
Source§fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Source§fn flush(&mut self) -> Result<(), Error>
fn flush(&mut self) -> Result<(), Error>
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)Auto Trait Implementations§
impl Freeze for FileWrite
impl RefUnwindSafe for FileWrite
impl Send for FileWrite
impl Sync for FileWrite
impl Unpin for FileWrite
impl UnsafeUnpin for FileWrite
impl UnwindSafe for FileWrite
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
impl<T> Erased for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more