Expand description
A fast cloneable reference that preserves reference structure during deep cloning.
Thread-safe (Send + Sync) and panic-safe. Uses Arc, parking_lot::RwLock,
and generation-based tracking for O(1) reference resolution during cloning.
§Example
use graph_clonable_ref::{RefGraph, GraphRef, deep_clone};
// Create a graph and some references
let graph = RefGraph::new();
let a = graph.create(42);
let b = a.clone(); // b points to same data as a
// Modify through one ref, visible through both
a.set(100);
assert_eq!(b.get(), 100);
// Create a struct holding both refs
let data = (a, b);
// Deep clone preserves structure: a' and b' point to SAME new data
let cloned = deep_clone(&data);
cloned.0.set(999);
assert_eq!(cloned.1.get(), 999); // Both see the change
assert_eq!(data.0.get(), 100); // Original unchangedModules§
- hashmap_
based - HashMap-based deep cloning for comparison. This is the traditional approach - slower due to hash lookups.
- index_
based - Two-phase index-based deep cloning (matching user’s approach).
Structs§
- Deep
Clone Guard - Guard that ensures clone generation and depth are reset even on panic.
- Graph
Ref - A cloneable reference that preserves structure during deep cloning.
- RefGraph
- Internal storage for a group of related references.
All
GraphRefs created from the sameRefGraphshare the underlying data.
Functions§
- begin_
deep_ clone - Begin a deep clone operation manually. Returns a guard that resets state on drop.
- deep_
clone - Perform a deep clone that preserves reference structure.