Cgp-serde: A modular serialization library for Serde powered by CGP

Rust devs split: new tool bends rules, boosts power

TLDR: cgp-serde lets Rust devs add context-aware data serialization that bypasses strict trait rules. The community split fast: some love the flexibility, others warn about complexity and safety—especially with comparisons to Scala’s rollback. Big deal because it challenges how Rust traits can be extended across projects.

Rust’s newest spark plug, cgp-serde, promises to let developers serialize and deserialize data while sidestepping Rust’s strict trait rules—and the comments lit up like a code review bonfire. The author, maybevoid, popped in with an AMA, tossing popcorn to the crowd while explaining Context-Generic Programming (CGP): think “plug-in behavior” based on the situation, not rigid one-size-fits-all traits. Fans cheered the freedom: finally, overlapping implementations without fighting Rust’s coherence cops! Skeptics, though, smelled trouble. The top worry? Safety-by-default becoming safety-by-optional, with some calling it “macro-powered cheat codes” for traits. One commenter name-dropped Scala, asking if this is the same trick they rolled back in Scala 3—translation: powerful idea, but could get messy. The vibe was classic Rust drama: half the thread swooning over arena-powered deserialization and dependency-injected contexts, the other half clutching their lifetimes and muttering about footguns. Jokes flew too: “Coherence? I hardly know her,” and “Serde now stands for ‘Some Extra Rules, Dude, Enjoy.’” Whether you see it as liberation or chaos, this is the kind of experimental power move that makes Rust’s community both excited and anxious. And the dev’s invitation to grill him only turned up the heat.

Key Points

  • cgp-serde introduces context-generic versions of Serde’s Serialize and Deserialize traits using CGP.
  • The approach enables overlapping and orphan implementations, bypassing Rust’s standard coherence restrictions in stable Rust.
  • Traits can be adapted with #[cgp_component], implemented with #[cgp_impl], and applied via delegate_components!.
  • CanSerializeValue replaces Self with a Value parameter and adds an &self context for dependency injection.
  • CanDeserializeValue similarly uses context and supports context-dependent strategies, e.g., arena-backed deserialization of borrowed values.

Hottest takes

"AMA about Context-Generic Programming" — maybevoid
"Didn’t Scala roll this idea back?" — carterschonwald
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.