Context-Generic Programming

Context-Generic Programming

@contextgeneric.dev

A new modular paradigm for Rust. Project account managed by @maybevoid.com. More info at https://contextgeneric.dev/

38 followers1 following56 posts

In short, cgp-serde extends Serde’s original Serialize and Deserialize traits with CGP, making it possible to write overlapping or orphaned implementations of these traits and thus bypass the standard Rust coherence restrictions.

I am thrilled to announce the release of CGP v0.5.0! This new release includes many exciting features and improvements, including auto dispatchers, extensible datatype improvements, monadic computation, emulation of RTN, sneak preview of cgp-serde. #RustLang contextgeneric.dev/blog/v0-5-0-...

contextgeneric.devCGP v0.5.0 Release - Auto dispatchers, extensible datatype improvements, monadic computation, RTN emulation, modular serde, and more | Context-Generic Programming

I will be presenting at RustLab on how to stop fighting with coherence and start writing context-generic programs with CGP. Use the discount code SP20FR to attend the conference with 20% discount!

Tired of fighting Rust’s coherence rules? S@maybevoid.com introduces Context-Generic Programming: a new way to write flexible trait impls without breaking the rules. 🧩 How to Stop Fighting with Coherence and Start Writing Context-Generic Trait Impls #rustlang #rustlab2025

Context-Generic Programming reposted

Tired of fighting Rust’s coherence rules? S@maybevoid.com introduces Context-Generic Programming: a new way to write flexible trait impls without breaking the rules. 🧩 How to Stop Fighting with Coherence and Start Writing Context-Generic Trait Impls #rustlang #rustlab2025

Now that Hypershell is finally published, it is finally time to go back to working on the core CGP implementation and add new features. The new CGP builder pattern is being developed pretty smoothly. Here is a snippet Rust code on the test code and macro expansion!

It is now possible to do OOP-like inheritance at the type-level in #RustLang using #CGP! Our latest PR brings significant improvements to defining and using presets in CGP, with support for multiple-inheritance, and override mechanism to overcome the diamond inheritance problem.

Now before you start wondering or getting disgusted, the inheritance in CGP is quite different from the classical inheritance in the OOP world. CGP presets are more like type-level dictionaries of generic mixins. So in a way, preset inheritance is sort of like extending type-level lookup tables.

This mainly improves use of CGP with idiomatic Rust code. Apparently, some readers pointed out about the aesthetic of getter methods returning &String instead of &str. This especially affects first impressions, when the hello world of CGP demonstrates the dependency injection of string fields.

There are also many other advanced improvements, such as allowing PhantomData tags and generic implementation of field accessors using AsRef. The PR covers high level overview of all changes. For detailed walk through, stay tuned for more blog posts and updates on the book.

You should still care about modularity, even if you don't write modular code yourself. Because modularity allows you to reuse modular code written by *others*, so that you can write much less non-modular code yourself. #CGP #RustLang

#CGP v0.3.0 has been released! This release includes a lot of QoL improvements, including the new `cgp_type!` and `#[cgp_getter]` macros, and the new `cgp-error-anyhow` crate. #RustLang The CGP Patterns book has also been updated with significant revision on based on the new features.

The error handling techniques are also useful for showing how various CGP patterns, such as associated types, can be used to solve various programming patterns. So once the readers understood CGP error handling, they can also apply the same patterns in other problem domains.

The error handling content is currently only partially completed. There are still a few more sub-chapters needed to walk through more complex cases of handling errors in real world applications. So stay tuned a little bit until the full chapter is completed.

We still need to finish the next chapter on error handling, before we can present a full practical use case of using CGP for real world applications. But hopefully this new chapter can give readers a better glimpse of how CGP can be useful for real world applications.