[−][src]Struct path_abs::FileWrite
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()?);
Methods
impl FileWrite
[src]
pub fn open<P: AsRef<Path>>(path: P, options: OpenOptions) -> Result<FileWrite>
[src]
Open the file with the given OpenOptions
but always sets write
to true.
pub fn create<P: AsRef<Path>>(path: P) -> Result<FileWrite>
[src]
Open the file in write-only mode, truncating it first if it exists and creating it otherwise.
pub fn open_append<P: AsRef<Path>>(path: P) -> Result<FileWrite>
[src]
Open the file for appending, creating it if it doesn't exist.
pub fn open_edit<P: AsRef<Path>>(path: P) -> Result<FileWrite>
[src]
Open the file for editing (reading and writing) but do not create it if it doesn't exist.
pub fn path(&self) -> &PathFile
[src]
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 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 From<FileWrite> for FileOpen
[src]
impl From<FileWrite> for File
[src]
impl AsRef<FileOpen> for FileWrite
[src]
impl AsRef<File> for FileWrite
[src]
impl Debug for FileWrite
[src]
impl Borrow<FileOpen> for FileWrite
[src]
impl Borrow<File> for FileWrite
[src]
impl<'a> Borrow<FileOpen> for &'a FileWrite
[src]
impl<'a> Borrow<File> for &'a FileWrite
[src]
impl Write for FileWrite
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
[src]
fn flush(&mut self) -> Result<()>
[src]
fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize, Error>
1.36.0[src]
Like write
, except that it writes from a slice of buffers. Read more
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0[src]
Attempts to write an entire buffer into this writer. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0[src]
Writes a formatted string into this writer, returning any error encountered. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
Creates a "by reference" adaptor for this instance of Write
. Read more
impl Seek for FileWrite
[src]
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
[src]
fn stream_len(&mut self) -> Result<u64, Error>
[src]
seek_convenience
)Returns the length of this stream (in bytes). Read more
fn stream_position(&mut self) -> Result<u64, Error>
[src]
seek_convenience
)Returns the current seek position from the start of the stream. Read more
Auto Trait Implementations
impl Unpin for FileWrite
impl Sync for FileWrite
impl Send for FileWrite
impl RefUnwindSafe for FileWrite
impl UnwindSafe for FileWrite
Blanket Implementations
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.
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,