Skip to main content

Crate graph_clonable_ref

Crate graph_clonable_ref 

Source
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 unchanged

Modules§

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§

DeepCloneGuard
Guard that ensures clone generation and depth are reset even on panic.
GraphRef
A cloneable reference that preserves structure during deep cloning.
RefGraph
Internal storage for a group of related references. All GraphRefs created from the same RefGraph share 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.