Expand description
§Foundation Utils
Core foundational utilities for the PromptFleet Agents project. Provides zero-dependency, WASM-compatible patterns for:
- RAII Guards: Automatic resource cleanup with Drop trait
- Scoped Operations: Guaranteed setup/teardown patterns
- Context Management: Thread-safe context propagation
- Resource Management: Safe resource acquisition/release
§Design Principles
- Zero Dependencies: Pure Rust stdlib only
- WASM Compatible: Designed for WebAssembly environments
- Zero Cost: Compile-time abstractions with no runtime overhead
- Exception Safe: Automatic cleanup even during panics
- Type Safe: Compiler-enforced correctness
§Usage
use foundation_utils::raii::Guard;
use foundation_utils::scoped::with_context;
// RAII guard for automatic cleanup
let _guard = Guard::new("my_resource", |r| {
println!("Cleaning up: {}", r);
});
// Scoped access to a value (value drops when scope ends)
let result = with_context(42, |ctx| {
ctx + 1
});
assert_eq!(result, 43);Re-exports§
pub use context::ContextManager;pub use context::ThreadLocalContext;pub use raii::Guard;pub use raii::ScopedGuard;pub use resource::ResourceGuard;pub use resource::ResourcePool;pub use scoped::ScopedBuilder;pub use scoped::ScopedCallback;pub use scoped::with_context;
Modules§
- context
- Context management patterns
- raii
- RAII (Resource Acquisition Is Initialization) patterns
- resource
- Resource management patterns
- scoped
- Scoped operations and callback patterns
Macros§
- context_
guard - Macro to create a context guard
- context_
key - Macro for creating context keys
- raii_
guard - Macro to create a simple RAII guard
- scoped_
operation - Macro for creating scoped operations
- with_
context_ scoped - Macro for scoped context operations
- with_
scoped_ context - Macro for creating context-based scoped operations
Constants§
- VERSION
- Version of the foundation utils
Functions§
- guard
- Create a simple RAII guard with cleanup function
- with_
scoped - Execute a function with scoped setup and cleanup