Expand description
Bracket pattern for resource management (Spec 206).
This module provides bracket-based resource management for debtmap operations, ensuring proper cleanup regardless of success or failure. It wraps stillwater’s bracket pattern with debtmap-specific resource helpers.
§Overview
The bracket pattern guarantees cleanup even on error:
bracket(acquire, release, use_resource)Resources are acquired, used, and then released in that order. The release function runs even if the use function fails.
§Available Resource Helpers
with_lock_file: Acquire exclusive access via lock filewith_temp_dir: Create and cleanup temporary directorywith_progress: Manage progress indicator lifecyclebracket_io: General bracket for I/O resources
§Example
ⓘ
use debtmap::resources::with_lock_file;
use debtmap::effects::effect_pure;
let effect = with_lock_file(
PathBuf::from("my.lock"),
|| effect_pure(42),
);
// Lock is acquired, effect runs, lock is released even on errorStructs§
- File
Handle - File handle resource for bracket-based file I/O.
- Lock
File - Lock file resource for exclusive access.
- Progress
Handle - Progress indicator resource.
- TempDir
- Temporary directory resource.
Functions§
- bracket_
io - General bracket for I/O resources with custom acquire/release.
- with_
file_ read - Open a file for reading, run an effect, then close it.
- with_
lock_ file - Acquire a lock file, run an effect, then release the lock.
- with_
progress - Show a progress bar during an effect, cleanup on completion.
- with_
spinner - Show a spinner during an effect, cleanup on completion.
- with_
temp_ dir - Create a temporary directory, run an effect with it, then cleanup.