cgp

Wire Rust components to providers using type-level tables and impl blocks.

1|Updated Nov 16, 2025
One-click install
npx skills add https://github.com/contextgeneric/cgp-skills --skill cgp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cgp
Source: https://github.com/contextgeneric/cgp-skills/tree/main/cgp
Command: npx skills add https://github.com/contextgeneric/cgp-skills --skill cgp

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

CGP provides a structured approach to dependency injection in Rust by moving interface constraints into impl blocks and using type-level tables to map components to providers per context. This enables multiple provider implementations for the same interface and allows swapping behavior by context without changing the consumer code.

Core Features & Use Cases

  • Type-level components and providers enable modular wiring that adapts to different contexts.
  • DelegateComponent tables map a provider to a concrete implementation for a given context, enabling pluggable behavior.
  • Blanket trait delegation and impl-side dependencies hide the wiring complexity behind clean trait interfaces.
  • Typical use cases include building context-specific plug-ins, testing with mock providers, and composing complex behavior across modules.

Quick Start

Define a CGP component with #[cgp_component], supply a provider with #[cgp_provider], and wire it to a context using delegate_components! or a DelegateComponent table. Then instantiate a concrete context and call the consumer method to observe the delegated provider in action.

Frequently Asked Questions about cgp

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement dependency injection in Rust without changing consumer code?

Dependency injection in Rust is implemented by moving interface constraints into impl blocks and using type-level tables to map components to providers per context. This enables swapping behavior by context without altering consumer code.

How do I use macros to wire modular providers in Rust?

You can use macros like #[cgp_component] and #[cgp_provider] to define components and providers, then wire them to a context using delegate_components! or a DelegateComponent table to assemble modular behavior.

What is the best way to swap implementations for testing in Rust contexts?

Swapping implementations for testing in Rust contexts is done by using DelegateComponent tables to map a provider to a concrete mock implementation. This allows pluggable behavior and context-specific providers without modifying the consumer interface.

Does CGP require type-level programming for composing complex modules?

CGP uses type-level components and providers to enable modular wiring that adapts to different contexts. It relies on type-level tables and blanket trait delegation to hide wiring complexity behind clean trait interfaces.

How do I map multiple provider implementations to the same Rust trait interface?

Mapping multiple provider implementations to the same Rust trait interface is done by applying DelegateComponent tables. This structure allows multiple concrete implementations per interface and enables blanket trait delegation across modules.