Crate anycow

Source
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-swap for the Updatable variant
  • Thread-Safe Options: Share data safely across threads
  • Zero-Cost Abstractions: Minimal overhead for common operations

§Storage Variants

§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();

Structs§

AnyCowReplaceError

Enums§

AnyCow
A supercharged container that can hold data in multiple storage formats, optimized for read-heavy, occasionally-updated scenarios.
AnyCowRef
A reference to data contained in an AnyCow.