LightClone

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

What It Does

LightClone is a trait and derive macro that only allows types that are cheap to clone:

  • Copy types - primitives, bitwise copies
  • Refcounted - Arc<T>, Rc<T> - just bump a counter
  • Persistent collections - imbl, rpds - structural sharing, O(1) clone

If you derive LightClone on a struct with an expensive field (like String), your code won't compile.

Why I Built It

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.

How It's Built

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.

Want more like this?

The best way to support my work is to like / comment / share this post on your favorite socials.