Skip to main content

deep_clone

Function deep_clone 

Source
pub fn deep_clone<T: Clone>(value: &T) -> T
Expand description

Perform a deep clone that preserves reference structure.

All GraphRefs pointing to the same data before cloning will point to the same (new) data after cloning. Thread-safe and panic-safe.

ยงExample

use graph_clonable_ref::{RefGraph, deep_clone};

let graph = RefGraph::new();
let a = graph.create(1);
let b = a.clone();

let (a2, b2) = deep_clone(&(a.clone(), b.clone()));

// a2 and b2 point to same NEW data
a2.set(42);
assert_eq!(b2.get(), 42);

// Original unchanged
assert_eq!(a.get(), 1);