TemporaryDirectoryHandle structv0.1.0

Source
A temporary directory that owns its name.
pub struct TemporaryDirectoryHandle {
    // private fields
}

Move-only, with the same contract as TemporaryFile: Close removes it and reports, destruction removes it quietly, Keep gives up ownership. Removal is of the directory itself and requires it to be empty — nothing here deletes a tree, because a temporary directory that silently erased whatever a caller put inside it would be a worse surprise than a refusal.

Associated functions

Create

pub func Create(
    allocator: Allocator,
    directory: Path,
    prefix: char8[..]
) -> TemporaryDirectoryHandle ! IoError

Creates a new temporary directory in directory, named from prefix and sixteen hex digits of entropy.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
directoryPaththe directory to create it in
prefixchar8[..]the text the generated name starts with

Returns: the created directory, which is removed when closed unless kept

Source

Methods

AsPath

pub func AsPath(self: &TemporaryDirectoryHandle) -> Path

The directory's path, for building names inside it.

Returns: the path it was created at

Source

Close

pub func Close(
    self: &var TemporaryDirectoryHandle,
    allocator: Allocator
) -> ! IoError

Removes the directory and reports what the removal said.

NameTypeDescription
allocatorAllocatorwhere the storage comes from

Returns: success when it was removed

Source

Keep

pub func Keep(self: &var TemporaryDirectoryHandle)

Leaves the directory where it is, giving up the name.

Source

Destructor

func ~TemporaryDirectoryHandle(self: &var TemporaryDirectoryHandle)

Removes the directory with the outcome discarded: the safety net, not the contract.

Source