cyrup_sugars 0.1.1

Syntactic sugar utilities for Rust - collections, async patterns, and macros
Documentation

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
  • hashbrown-json - 🔥 Amazing hashbrown HashMap macros with full JSON object 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 JSON Syntax (with hashbrown-json 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"]"#)?;