Providers
Context-Generic Programming (CGP) lets a context choose the provider behind each trait
call, and a provider is a zero-sized type wired to a component to say how that component is
implemented for a context, the type the implementation runs
against. Providers carry no runtime value; they are type-level markers named in a
delegate_components! table and resolved at compile time. This
page groups the providers CGP ships by the job they do, in roughly the order most CGP code reaches
for them.
If you are new to CGP, start with the reference overview rather than here; this page is the fuller map for once the essentials are familiar.
Wiring an everyday component
UseContext implements a provider trait by routing back through the context's
own consumer-trait implementation. A
higher-order provider falls back to it, and a
dispatch combinator routes each matched case through it as its default per-variant provider.
UseType supplies a concrete type for an abstract-type component, so a context
binds its error type or runtime with one wiring line. UseField implements a
getter by reading a context field named by a tag, and UseFields does the same
when every getter method reads a same-named field. UseDefault selects a
component's own default method bodies when there is no behavior left for a provider to supply.
WithProvider is the adapter behind the With… aliases: it turns a foundational
provider such as a field getter or a type provider into a provider for a named component, and the
aliases WithField, WithType, WithContext,
WithFieldRef, and WithDelegatedType are how it
usually appears in wiring.
Dispatching per type, and organizing wiring
UseDelegate chooses a provider by the type of a generic parameter through a
lookup table, the legacy form of the per-type dispatch the
open statement now expresses.
RedirectLookup routes a component's lookup along a type-level path in a
separate table, the mechanism every namespace and open statement rides.
Both are read in wiring far more often than written.
The specialized getters and type providers
UseFieldRef is the foundational getter that borrows a field through AsRef,
for a getter that returns a view of a field the context stores as a different type.
ChainGetters composes a list of getters to reach a field several hops inside
a nested context. UseDelegatedType resolves an
abstract type through a table rather than fixing it to one
concrete type. Each is reached through WithProvider when wired to a named
component; UseDelegatedType alone is also wired directly to the built-in TypeProviderComponent.
The computation-family combinators
The handler family has its own providers, which build, route, and lift computations rather than wire a single trait. The error providers raise and wrap a context's abstract error, the handler combinators compose and promote handlers across the family's synchronous, async, and fallible shapes, the dispatch combinators route an extensible-data value to per-field or per-variant handlers, and the monad providers chain handlers that short-circuit through a monad. Each group is a subsection here with one page per provider and its own overview.
An AI agent wrote this page using the CGP knowledge base. Its content was verified against the library's source. See How AI is used in this project.