cgp v0.6.0
Version 0.6.0 of cgp, the library for Context-Generic Programming (CGP) that enables pluggable trait implementations in Rust, lets a provider be written like a blanket impl of its consumer trait and lets a context own its wiring table. This page lists every change a user can see and the steps that take a project there from v0.5.0.
Released on 2025-10-26.
- Release post: CGP v0.6.0 Release: Major ergonomic improvements for provider and context implementations
- Crate:
cgp0.6.0 on crates.io - Changes: v0.5.0...v0.6.0
Summary
#[cgp_impl] writes a provider as an impl of its consumer trait, and delegate_components! accepts the context type itself, so a context needs no separate table struct. Consumer traits now route through DelegateComponent, which removes the HasCgpProvider trait. #[cgp_context] keeps working through a blanket DelegateComponent impl, and #[cgp_inherit] lets a context inherit a preset.
Compatibility
- Minimum Rust version: 1.89, unchanged from v0.5.0.
- Released together: the workspace's 23 crates published on crates.io, all at 0.6.0.
Upgrading
A project moving from v0.5.0 takes these steps, in this order:
- Change the version to
cgp = "0.6.0". - Replace
HasCgpProviderwhere the project names the trait or implements it by hand, per the removal. A context declared with#[cgp_context]and a provider declared with#[cgp_provider]need no change.
Breaking changes
HasCgpProvider is removed
The trait HasCgpProvider and its CgpProvider associated type are removed from the prelude and from cgp::core::component (#175). The blanket impls of consumer traits and CanUseComponent now look a context's provider up through DelegateComponent.
- Old:
HasCgpProvidergave a context its provider table throughtype CgpProvider, and a consumer-trait blanket impl requiredContext: HasCgpProviderandContext::CgpProvider: Provider<Context>. - New: the blanket impl requires
Context: DelegateComponent<Component>andContext::Delegate: Provider<Context>.#[cgp_context]generatesimpl<Name> DelegateComponent<Name> for App { type Delegate = AppComponents; }, so a context that it declares works unchanged. - What to do: replace a hand-written
impl HasCgpProvider for Ctx { type CgpProvider = Table; }withimpl<Name> DelegateComponent<Name> for Ctx { type Delegate = Table; }, or wire the context directly as the new feature describes. Replace a boundC: HasCgpProviderwithC: DelegateComponent<Component>, andC::CgpProviderwithC::Delegate.
New features
Providers
#[cgp_impl]writes a provider as an impl of its consumer trait. The impl keeps the consumer trait's signature, with the context in theSelfposition, and the macro rewrites it into the provider-trait shape and generates theIsProviderForimpl (#174). The attribute names the provider type, optionally afternewto declare its struct, and optionally names the component after a colon, as#[cgp_impl(new GreetHello: GreeterComponent)]. The prelude exports it. See#[cgp_impl].
Contexts
- A context implements the consumer traits of the components it wires directly.
delegate_components!accepts the context type, as indelegate_components! { App { GreeterComponent: GreetHello } }, so a separateAppComponentsstruct is unnecessary (#175). The context may also implement the consumer trait of a component it does not wire by hand. #[cgp_inherit]makes a context inherit a preset.#[cgp_inherit(MyPreset)]on a struct replaces#[cgp_context(AppComponents: MyPreset)], with no intermediateAppComponentsstruct (#176). The prelude exports it.
Fixes
selfin a default method body: a default body in a#[cgp_component]trait may useself, which the macro rewrites to the context in the provider trait, where v0.5.0 failed withE0424(#179).
An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its content was verified against the library's source at the release's tag. See How AI is used in this project.