Expand description
§Cyrup Sugars
Syntactic sugar utilities for Rust - collections, async patterns, and macros.
This crate provides ergonomic utilities organized into feature-gated modules:
§Features
collections- Enhanced collection types likeZeroOneOrMany,OneOrMany, andByteSizeasync- Async utilities with the “always unwrapped” pattern usingAsyncTaskandAsyncStreammacros- Convenient macros for collections and async operationsarray-tuples- 🔥 Amazing hashbrown HashMap macros with array tuple syntax supportgix-interop- Git object ID optimized hash tables
§Example
use cyrup_sugars::collections::ByteSizeExt;
use cyrup_sugars::{AsyncTask, AsyncResult};
// Ergonomic byte sizes
let cache_size = 512.mb();
println!("Cache size: {} bytes", cache_size.as_bytes());
// Type-safe async operations (no raw Results allowed)
let task = AsyncTask::from_value(42);
// let bad_task = AsyncTask::from_value(Ok(42)); // Compile error!§🔥 Hashbrown Array Tuple Syntax (with array-tuples feature)
ⓘ
use cyrup_sugars::collections::{ZeroOneOrMany, OneOrMany};
use cyrup_sugars::macros::hashbrown::hash_map;
use serde_json;
// Semantic JSON mapping with blazing fast hashbrown
let config = hash_map! {
"servers" => ZeroOneOrMany::many(vec!["api.com", "db.com"]),
"endpoints" => OneOrMany::one("primary.api.com")
};
let json = serde_json::to_string_pretty(&config)?;
// Flexible deserialization - handles null, single values, or arrays
let from_null: ZeroOneOrMany<String> = serde_json::from_str("null")?;
let from_single: ZeroOneOrMany<String> = serde_json::from_str(r#""hello""#)?;
let from_array: ZeroOneOrMany<String> = serde_json::from_str(r#"["hello", "world"]"#)?;Re-exports§
pub use sugars_collections as collections;pub use sugars_macros as macros;pub use sugars_builders as builders;
Modules§
- async
- Async utilities with the “always unwrapped” pattern.
- closures
- Closure macros for elegant stream processing with zero-allocation pattern matching
- prelude
- Prelude module that brings common macros and types into scope
Macros§
- await_
ok - Creates an async closure that processes successful values with the provided pattern and body. Available when both ‘macros’ and any async feature are enabled.
- await_
result - Creates an async closure that processes results with the provided pattern and body. Available when both ‘macros’ and any async feature are enabled.
- on_
error - Creates a closure that handles errors with the provided expression. Available when both ‘macros’ and any async feature are enabled.
- on_
result - Creates a closure that handles Result values with separate expressions for Ok and Err cases. Available when both ‘macros’ and any async feature are enabled.
Structs§
- Async
Result - A Result type that can be used with AsyncTask
- Async
Result Chunk - A Result type for streaming chunks that can be used with AsyncStream
- Async
Stream - Generic async stream wrapper for streaming operations with Tokio
- Async
Task - Generic async task wrapper for single operations
- Byte
Size - Represents a size in bytes with semantic constructors
- OneOr
Many - A non-empty collection that holds one or many values of type
T.
Enums§
- Zero
OneOr Many - A collection that can hold zero, one, or many values of type
T.
Traits§
- Byte
Size Ext - Extension trait to add .bytes() method to integers
- Future
Ext - Extension trait for futures that provides additional combinators for async operations.
- NotResult
- Marker trait to prevent Result types in AsyncTask/AsyncStream
- Stream
Ext - Extension trait for streams that provides additional combinators for async stream operations.