pub trait TempFile: TempResource {
// Required method
fn persist(
self: Box<Self>,
target: &FsPath,
options: &PersistOptions,
) -> FsResult<WriteOutcome>;
// Provided methods
fn open_reader(
&self,
options: &ReadOptions,
) -> FsResult<Box<dyn FileReader>> { ... }
fn open_writer(
&self,
options: &WriteOptions,
) -> FsResult<Box<dyn FileWriter>> { ... }
fn read_all(&self) -> FsResult<Vec<u8>> { ... }
fn write_all(&self, bytes: &[u8]) -> FsResult<WriteOutcome> { ... }
}Expand description
Temporary file handle with cleanup responsibility.
Required Methods§
Sourcefn persist(
self: Box<Self>,
target: &FsPath,
options: &PersistOptions,
) -> FsResult<WriteOutcome>
fn persist( self: Box<Self>, target: &FsPath, options: &PersistOptions, ) -> FsResult<WriteOutcome>
Persists the temporary file to a target path.
§Parameters
target: Final target path.options: Persistence options.
§Returns
Write outcome for the persisted resource.
§Errors
Returns crate::FsError when persistence fails.
Provided Methods§
Sourcefn open_reader(&self, options: &ReadOptions) -> FsResult<Box<dyn FileReader>>
fn open_reader(&self, options: &ReadOptions) -> FsResult<Box<dyn FileReader>>
Opens the temporary file for reading.
§Parameters
options: Read options.
§Returns
Reader handle opened by the owning filesystem.
§Errors
Returns crate::FsError when the owning filesystem cannot open the
temporary file for reading.
Sourcefn open_writer(&self, options: &WriteOptions) -> FsResult<Box<dyn FileWriter>>
fn open_writer(&self, options: &WriteOptions) -> FsResult<Box<dyn FileWriter>>
Opens the temporary file for writing.
§Parameters
options: Write options.
§Returns
Writer handle opened by the owning filesystem.
§Errors
Returns crate::FsError when the owning filesystem cannot open the
temporary file for writing.
Sourcefn read_all(&self) -> FsResult<Vec<u8>>
fn read_all(&self) -> FsResult<Vec<u8>>
Reads the whole temporary file into memory.
§Returns
Complete temporary file bytes.
§Errors
Returns crate::FsError when opening or reading fails.
Sourcefn write_all(&self, bytes: &[u8]) -> FsResult<WriteOutcome>
fn write_all(&self, bytes: &[u8]) -> FsResult<WriteOutcome>
Writes all bytes to the temporary file and commits the writer.
§Parameters
bytes: Bytes to write.
§Returns
Write outcome reported by the owning filesystem.
§Errors
Returns crate::FsError when opening, writing, aborting, or committing
fails.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".