Skip to main content
Context-Generic Programming

Build modular Rust applications with zero-cost abstractions

Why Context-Generic Programming?

Modular Component System

Modular Component System

Decouple interface definitions from implementations using provider traits. Write multiple context-generic providers that can coexist without conflicts.

Highly Expressive Macros

Highly Expressive Macros

Write abstract programs generic over contexts without managing long lists of generic parameters. Achieve expressiveness rivaling dynamic languages.

Type-Safe Composition

Type-Safe Composition

All component wiring is verified at compile time. Missing dependencies are caught early, with no runtime errors possible from CGP constructs.

No-Std Friendly

No-Std Friendly

Build fully abstract programs without concrete dependencies. Deploy to embedded systems, kernels, WebAssembly, or symbolic execution platforms.

Zero-Cost Abstraction

Zero-Cost Abstraction

All CGP operations happen at compile time using Rust's type system. No runtime overhead, upholding Rust's zero-cost abstraction guarantee.

Bypass Coherence Rules

Bypass Coherence Rules

Enable overlapping and orphan trait implementations without restriction. Define implementations for types you don't own and traits you don't control.

Bypass Coherence Restrictions

CGP enables you to write overlapping and orphan implementations of any trait, breaking free from Rust's coherence rules while maintaining type safety.

Annotate any trait with #[cgp_component], write named implementations with #[cgp_impl], and selectively enable them using delegate_components!.

Learn More
#[cgp_component(HashProvider)]
pub trait Hash { ... }

#[cgp_impl(HashWithDisplay)]
impl HashProvider
where
Self: Display,
{ ... }

delegate_components! {
MyData {
HashProviderComponent: HashWithDisplay,
}
}

Common Rust Problems, Solved

⚡ No More Monolithic Traits

Break down large traits into small, focused components. Compose features without trait bounds propagating everywhere.

🔄 Overlapping Implementations

Implement traits in multiple ways without newtype wrappers. Choose the right implementation for your context.

🎯 Decouple Dependencies

Write core logic independent of error handling, async runtimes, or serialization libraries. Wire them up at the edges.

Ready to Get Started?

CGP is in active development and perfect for early adopters who want to experiment with advanced Rust patterns.