Note - LastUpdated: 2026.02.02 | 1 min read (202 words)
light-clone | projects | rust
DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)
TL;DR - A Rust derive macro that enforces cheap clones at compile time.
Related posts can be found under tag light-clone
LightClone is a trait and derive macro that only allows types that are cheap to clone:
Arc<T>, Rc<T> - just bump a counterimbl, rpds - structural sharing, O(1) cloneIf you derive LightClone on a struct with an expensive field (like String), your code won't compile.
In Rust, cheap and expensive clones look identical - both use .clone(). When writing High Level Rust with liberal cloning, it's easy to accidentally add an expensive field during refactoring and tank performance with zero compiler warnings. And expensive clones in Rust are very expensive.
LightClone turns invisible performance footguns into compiler errors.
A marker trait that requires Clone, plus a derive macro that validates all fields implement LightClone at compile time. The actual cloning delegates to .clone() - the trait just provides compile-time safety.
Feature flags enable support for ecosystem crates: imbl, rpds, bytes, smol_str, uuid, chrono, and more.
The best way to support my work is to like / comment / share this post on your favorite socials.