Skip to main content

TempFile

Trait TempFile 

Source
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§

Source

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§

Source

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.

Source

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.

Source

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.

Source

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".

Implementors§