1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/// Marker trait for types that are O(1) to clone.
///
/// `LightClone` is a marker trait that asserts a type's `Clone` implementation is cheap.
/// Cloning involves only:
/// - Atomic refcount increments (Arc)
/// - Non-atomic refcount increments (Rc)
/// - Bitwise copy (Copy types)
/// - Persistent data structure cloning (im, imbl, rpds)
///
/// This trait is similar to Facebook's [Dupe](https://github.com/facebookincubator/gazebo)
/// crate but provides a `.light_clone()` method that delegates to `clone()`.
///
/// # Usage
///
/// Prefer `.light_clone()` over `.clone()` when you want to make the cheap clone explicit:
///
/// ```
/// use light_clone::LightClone;
///
/// let x: i32 = 42;
/// let y = x.light_clone(); // Explicit: this is a light clone
/// assert_eq!(x, y);
/// ```
///
/// A shorthand `.lc()` method is also available:
///
/// ```
/// use light_clone::LightClone;
///
/// let x: i32 = 42;
/// let y = x.lc(); // Shorthand for light_clone()
/// assert_eq!(x, y);
/// ```
///
/// # Derive Macro
///
/// Use `#[derive(Clone, LightClone)]` on structs to get compile-time enforcement that all
/// fields are cheap to clone. The derive macro requires `Clone` to be implemented separately
/// (either via derive or manual impl) and generates a `LightClone` impl with bounds that
/// ensure all fields implement `LightClone`:
///
/// ```ignore
/// use light_clone::LightClone;
/// use std::sync::Arc;
///
/// #[derive(Clone, LightClone)]
/// struct Person {
/// id: i64,
/// name: Arc<str>,
/// }
/// ```
///
/// The compile-time enforcement comes from the generated bounds - if any field doesn't
/// implement `LightClone`, compilation will fail.