Skip to main content

TempFile

Struct TempFile 

Source
pub struct TempFile { /* private fields */ }
Expand description

Temporary file retaining the provider session until its lifecycle completes.

Dropping this synchronous handle while its state is TempResourceState::Owned or TempResourceState::CleanupRequired calls provider cleanup synchronously on the current thread. Cleanup may perform I/O and block, and any cleanup error is ignored. Call Self::cleanup explicitly when the result matters; if it fails and leaves the state as CleanupRequired, dropping the handle may make another best-effort cleanup attempt. The facade does not call cleanup on drop in the Cleaned, Persisted, Kept, or Indeterminate states.

This contract applies to synchronous handles. Async handles use their separate cancel_on_drop behavior, and rejected handles use their isolated recovery contract; neither implies synchronous cleanup by dropping this type.

§Examples

use qubit_fs::FileSystem;
use qubit_fs::temp::{TempOptions, TempResourceState};

fn create_and_cleanup(filesystem: &FileSystem) -> Result<(), Box<dyn std::error::Error>> {
    let mut temporary = filesystem.create_temp_file(TempOptions::default())?;
    assert_eq!(TempResourceState::Owned, temporary.state());
    temporary.cleanup()?;
    assert_eq!(TempResourceState::Cleaned, temporary.state());
    Ok(())
}

Implementations§

Source§

impl TempFile

Source

pub const fn path(&self) -> &Path

Returns the temporary logical path.

§Returns

The provider-local path retained by this handle.

Source

pub const fn state(&self) -> TempResourceState

Returns the resource lifecycle state.

§Returns

The current ownership and cleanup state.

Source

pub fn persist( &mut self, target: &Path, options: PersistOptions, ) -> Result<PersistOutcome, PersistFailure>

Persists this temporary file to target.

§Parameters
  • target: Destination path validated by the owning filesystem.
  • options: Atomicity and publication requirements.
§Returns

The provider-confirmed publication outcome.

§Errors

Returns a typed failure for invalid lifecycle state, failed preflight, provider failure, or a provider contract violation.

Source

pub fn keep(&mut self) -> Result<PersistOutcome, PersistFailure>

Publishes this temporary file to the provider-generated target.

§Returns

The provider-confirmed publication outcome and generated target.

§Errors

Returns a typed failure when ownership is unavailable, provider publication fails, or the provider returns an invalid target.

Source

pub fn cleanup(&mut self) -> FsResult<()>

Cleans the source and releases the session responsibility.

Call this method when cleanup success or failure must be observed. Unlike dropping an owned handle, this returns the provider result. If cleanup fails while the state remains CleanupRequired, a later drop may make another best-effort attempt.

§Errors

Returns an invalid-state error when cleanup is no longer legal, or the provider cleanup error when cleanup cannot be confirmed.

Trait Implementations§

Source§

impl Debug for TempFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult

Formats the handle path and lifecycle state without exposing provider internals.

§Parameters
  • f: Formatter that receives the debug representation.
§Returns

Ok(()) when formatting succeeds, or the formatter’s error.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.