foundation_utils
Crate: foundation_utils · Path: crates/foundation_utils
Description (Cargo.toml): Foundation utilities for RAII patterns, resource management, and scoped operations
Core foundational utilities for the PromptFleet Agents project. Provides zero-dependency, WASM-compatible patterns for RAII guards, scoped operations, context management, and resource pools. Pure Rust stdlib — no runtime overhead, automatic cleanup even during panics.
Feature flags
Section titled “Feature flags”From crates/foundation_utils/Cargo.toml:
No feature flags declared. (default = [], core functionality has zero dependencies.)
Optional dependencies web-time and wasm-bindgen exist but are not gated behind named features.
Public API (from src/lib.rs)
Section titled “Public API (from src/lib.rs)”Modules: context, raii, resource, scoped.
Re-exports:
ContextManager,ThreadLocalContext— thread-safe context propagationGuard,ScopedGuard— RAII guards with Drop-based cleanupResourceGuard,ResourcePool— safe resource acquisition/releasewith_context,ScopedBuilder,ScopedCallback— scoped operation helpers
Top-level convenience functions:
guard(resource, cleanup)— create a simple RAII guardwith_scoped(setup, work, cleanup)— execute a function with guaranteed setup/teardown
Constant: VERSION.
Example sketch
Section titled “Example sketch”use foundation_utils::{guard, with_scoped};
// RAII guard — cleanup runs automatically when _g dropslet _g = guard("my_resource", |r| println!("Cleaning up: {}", r));
// Scoped operation — guaranteed setup/teardownlet result = with_scoped( || 42, |resource| *resource + 10, |resource| println!("cleanup: {}", resource),);assert_eq!(result, 52);Full API reference: cargo doc -p foundation_utils --no-deps