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
impl TempFile
Sourcepub const fn state(&self) -> TempResourceState
pub const fn state(&self) -> TempResourceState
Sourcepub fn persist(
&mut self,
target: &Path,
options: PersistOptions,
) -> Result<PersistOutcome, PersistFailure>
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.
Sourcepub fn keep(&mut self) -> Result<PersistOutcome, PersistFailure>
pub fn keep(&mut self) -> Result<PersistOutcome, PersistFailure>
Sourcepub fn cleanup(&mut self) -> FsResult<()>
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.