Skip to main content

Type-level strings and paths

Recovering a field name as runtime data, and joining the paths a lookup follows.

Overview​

Context-Generic Programming (CGP) encodes field and variant names as types, so that a name can drive trait resolution. A program eventually needs those names as ordinary strings, to report a missing field or to build a key, and two of these traits are how a name comes back out, while the third joins the type-level paths a redirected lookup follows. None of them is in the prelude, and they sit in two different modules, which is the group's sharpest edge.

  • StaticString decodes a Symbol! into a compile-time &'static str constant. This is the one to reach for when you need a name as data. Import it from cgp::core::field::traits.
  • StaticFormat writes a type-level string into a formatter, and backs the Display impl on Symbol, so a Display bound is usually all you need. Reach for the trait itself only where a value to format is missing. Import it from cgp::core::base::traits.
  • ConcatPath joins two type-level Path! routes, the path-level analogue of ConcatProduct. Import it from cgp::core::base::traits.

The ideas behind them​

  • Namespaces: reusable wiring tables and the paths that route into them.
  • Extensible records: where field-name types are put to work at scale.

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.