Struct staged_file::StagedFile
source · pub struct StagedFile { /* private fields */ }
Expand description
Creates a temporary file which can then be committed to a final path.
Implementations§
source§impl StagedFile
impl StagedFile
sourcepub fn with_final_path<P>(final_path: P) -> Result<Self, Error>where
P: AsRef<Path>,
pub fn with_final_path<P>(final_path: P) -> Result<Self, Error>where P: AsRef<Path>,
Instantiates a new staged file with the desired final path.
The desired final path is where the file contents should be if the staged file is committed.
A temporary directory and file are created during this function call.
Important
If a file exists at the desired final file path, it will be overwritten.
Errors
If the final path is invalid (e.g. is a directory) or if the final path’s
parent directory cannot be determined, an Error
will be returned.
Any I/O error which occurs when creating the temporary directory or file will also be returned.
sourcepub fn with_final_path_and_temp_dir_prefix<P>(
final_path: P,
temp_dir_prefix: Option<&str>
) -> Result<Self, Error>where
P: AsRef<Path>,
pub fn with_final_path_and_temp_dir_prefix<P>( final_path: P, temp_dir_prefix: Option<&str> ) -> Result<Self, Error>where P: AsRef<Path>,
Instantiates a new staged file with the desired final path and a temporary directory prefix.
The desired final path is where the file contents should be if the staged file is committed.
A temporary directory and file are created during this function call. The temporary directory will have the prefix given or a default prefix will be chosen.
Important
If a file exists at the desired final file path, it will be overwritten.
Errors
If the final path is invalid (e.g. is a directory) or if the final path’s
parent directory cannot be determined, an Error
will be returned.
Any I/O error which occurs when creating the temporary directory or file will also be returned.
sourcepub fn commit(self) -> Result<(), Error>
pub fn commit(self) -> Result<(), Error>
Commits the temporary file contents into the desired final path.
If the contents should not be committed, then allow the StagedFile
to
be dropped without calling commit.
Important
If a file exists at the desired final file path, it will be overwritten.
Errors
Any I/O errors encountered will be returned.
Trait Implementations§
source§impl Debug for StagedFile
impl Debug for StagedFile
source§impl Drop for StagedFile
impl Drop for StagedFile
source§impl Read for &StagedFile
impl Read for &StagedFile
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
read
, except that it reads into a slice of buffers. Read moresource§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf
. Read moresource§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
buf
. Read moresource§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf
. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)source§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,
Read
. Read moresource§impl Read for StagedFile
impl Read for StagedFile
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
read
, except that it reads into a slice of buffers. Read moresource§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf
. Read moresource§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
buf
. Read moresource§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf
. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)source§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,
Read
. Read moresource§impl Seek for &StagedFile
impl Seek for &StagedFile
source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
source§fn stream_position(&mut self) -> Result<u64>
fn stream_position(&mut self) -> Result<u64>
source§impl Seek for StagedFile
impl Seek for StagedFile
source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
source§fn stream_position(&mut self) -> Result<u64>
fn stream_position(&mut self) -> Result<u64>
source§impl Write for &StagedFile
impl Write for &StagedFile
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 write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
source§fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)source§impl Write for StagedFile
impl Write for StagedFile
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 write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
source§fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)