Skip to main content

Crate foundation_utils

Crate foundation_utils 

Source
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