Skip to main content

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.

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:

  1. Change the version to cgp = "0.6.0".
  2. Replace HasCgpProvider where 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: HasCgpProvider gave a context its provider table through type CgpProvider, and a consumer-trait blanket impl required Context: HasCgpProvider and Context::CgpProvider: Provider<Context>.
  • New: the blanket impl requires Context: DelegateComponent<Component> and Context::Delegate: Provider<Context>. #[cgp_context] generates impl<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; } with impl<Name> DelegateComponent<Name> for Ctx { type Delegate = Table; }, or wire the context directly as the new feature describes. Replace a bound C: HasCgpProvider with C: DelegateComponent<Component>, and C::CgpProvider with C::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 the Self position, and the macro rewrites it into the provider-trait shape and generates the IsProviderFor impl (#174). The attribute names the provider type, optionally after new to 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 in delegate_components! { App { GreeterComponent: GreetHello } }, so a separate AppComponents struct 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 intermediate AppComponents struct (#176). The prelude exports it.

Fixes​

  • self in a default method body: a default body in a #[cgp_component] trait may use self, which the macro rewrites to the context in the provider trait, where v0.5.0 failed with E0424 (#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.