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 collectionsgix-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
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;
Run the examples to see the library in action:
```bash
# Array tuple syntax
cd examples/array_tuple_syntax && cargo run
# Async task pipeline
cd examples/async_task_example && cargo run
# Collection types
cd examples/one_or_many_example && cargo run
cd examples/zero_one_or_many_example && cargo run
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.