sugars

Syntactic sugar utilities for Rust - collections, async patterns, and macros.
Features
collections- Collection types:ZeroOneOrMany,OneOrMany,ByteSizeasync- Async utilities:AsyncTaskandAsyncStreammacros- Collection and async macrosarray-tuples- Array tuple syntax for collectionsbuilders- Builder traits:MessageChunk,ChunkHandlergix-interop- Git object hash tables
Array Tuple Syntax
The array-tuples feature enables intuitive array tuple syntax in builder patterns:
let builder = agent_role
.additional_params
.metadata
.tools;
Implementation Pattern:
/// Set additional parameters with array tuple syntax
Usage: .additional_params([("beta", "true"), ("debug", "false")])
The array tuple syntax [("key", "value")] works seamlessly with the IntoHashMap trait, providing a clean and intuitive API for developers.
π For complete implementation details, see the Array Tuple Syntax Implementation Guide
AsyncTask Pattern
The async feature provides concrete async types that avoid boxed futures:
use AsyncTask;
use ZeroOneOrMany;
// Single receiver
let task = new;
// Multiple receivers (first result wins)
let task = new;
// From future
let task = from_future;
let result = task.await;
AsyncTask supports single and multiple receivers using the ZeroOneOrMany pattern, enabling race conditions, fallback patterns, and load balancing.
π For complete usage examples, see the AsyncTask Usage Guide
Collection Types
The collections feature provides memory-efficient collection types for different scenarios:
use ;
// OneOrMany: Non-empty collections (guaranteed at least one element)
let servers = many.unwrap;
let primary = servers.first; // Always exists
// ZeroOneOrMany: Flexible collections (zero allocations for None/One)
let middleware = none;
let middleware = middleware.with_pushed;
let middleware = middleware.with_pushed;
match middleware
Both types support JSON serialization, builder patterns, and zero-allocation optimizations for small collections.
π For complete guides, see OneOrMany Guide and ZeroOneOrMany Guide
Builder Traits
The builders feature provides traits for message chunk handling:
MessageChunk- Trait for types that can represent both success and error statesChunkHandler<T, E>- Handles streamingResult<T, E>by unwrapping toT
These traits enable consistent error handling patterns across builders with a single on_chunk method that handles both success and error cases.
π For complete implementation guide, see the ChunkHandler Pattern Guide - Step-by-step instructions for implementing the full pattern from scratch.
Quick Start
Add this to your Cargo.toml:
[]
= "0.1.0"
Or with specific features:
[]
= { = "0.1", = ["array-tuples"] }
Example
let stream = agent_role
.completion_provider
.temperature
.max_tokens
.system_prompt
.context
.bin.init
.tools // ZeroOneOrMany `Tool` || `McpTool` || NamedTool (WASM)
.additional_params
.memory
.metadata
.on_tool_result
.on_conversation_turn
.on_chunk
.into_agent // Agent Now
.conversation_history
.chat? // AsyncStream<MessageChunk
.collect;
## Working Examples
### Message Chunk Handling
The `builders` feature provides powerful traits for handling streaming message chunks:
```rust
use *;
use *;
// MessageChunk trait - implemented by chunk types
// ChunkHandler trait - processes Result<T, E> streams
let builder = builder
.on_chunk;
Array Tuple Syntax
// All these patterns work with array tuple syntax:
new
.additional_params
.metadata
Run Examples
# Array tuple syntax with on_chunk method
&&
# Async task pipeline
&&
# Collection types
&&
&&
Testing
Run tests with full coverage:
# Run all tests
# Generate coverage report
Documentation
Generate and view documentation:
Benchmarks
Run performance benchmarks:
Contributing
Contributions are welcome! Please ensure:
- All tests pass:
cargo test --all-features - Code is formatted:
cargo fmt - No clippy warnings:
cargo clippy --all-features -- -D warnings - Documentation is updated:
cargo doc --all-features - Examples work:
cargo run --example <name> --features <features>
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.