Crate cyrup_sugars

Crate cyrup_sugars 

Source
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 like ZeroOneOrMany, OneOrMany, and ByteSize
  • async - Async utilities with the “always unwrapped” pattern using AsyncTask and AsyncStream
  • macros - Convenient macros for collections and async operations
  • array-tuples - 🔥 Amazing hashbrown HashMap macros with array tuple syntax support
  • gix-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§

AsyncResult
A Result type that can be used with AsyncTask
AsyncResultChunk
A Result type for streaming chunks that can be used with AsyncStream
AsyncStream
Generic async stream wrapper for streaming operations with Tokio
AsyncTask
Generic async task wrapper for single operations
ByteSize
Represents a size in bytes with semantic constructors
OneOrMany
A non-empty collection that holds one or many values of type T.

Enums§

ZeroOneOrMany
A collection that can hold zero, one, or many values of type T.

Traits§

ByteSizeExt
Extension trait to add .bytes() method to integers
FutureExt
Extension trait for futures that provides additional combinators for async operations.
NotResult
Marker trait to prevent Result types in AsyncTask/AsyncStream
StreamExt
Extension trait for streams that provides additional combinators for async stream operations.