Expand description
§AnyCow - A Supercharged Container for Read-Heavy, Update-Light Data
AnyCow is a versatile, high-performance container that extends the concept of Cow
(Clone-on-Write) with multiple storage strategies optimized for different use cases.
It’s perfect for scenarios where you need to read values frequently but update them
only occasionally.
§Features
- Multiple Storage Strategies: Choose the right storage for your use case
- Lock-Free Updates: Atomic updates using
arc-swapfor theUpdatablevariant - Thread-Safe Options: Share data safely across threads
- Zero-Cost Abstractions: Minimal overhead for common operations
§Storage Variants
AnyCow::Borrowed- Zero-cost references for temporary dataAnyCow::Owned- Heap-allocated owned data viaBox<T>AnyCow::Shared-Arc<T>for shared immutable data across threadsAnyCow::Updatable- Lock-free atomic updates usingarc-swapAnyCow::Lazy- Lazy initialization with atomic updates for static contexts
§Quick Example
use anycow::AnyCow;
// Create from different sources
let borrowed = AnyCow::borrowed(&"hello");
let owned = AnyCow::owned(String::from("world"));
let updatable = AnyCow::updatable(vec![1, 2, 3]);
let lazy = AnyCow::lazy(|| vec![7, 8, 9]);
// Read values efficiently
println!("{}", *borrowed.borrow()); // "hello"
println!("{}", *owned.borrow()); // "world"
// Atomic updates (lock-free!)
updatable.try_replace(vec![4, 5, 6]).unwrap();
lazy.try_replace(vec![10, 11, 12]).unwrap();