Skip to main content

Types

The types the library is built from: the type-level building blocks that carry information in the type system, and the one ordinary runtime type you return from a getter.

Overview​

In Context-Generic Programming (CGP), most types on these pages are type-level building blocks, and you read them far more often than you write them. Much of CGP's machinery runs at the type level, where a field name, a variant, a position, or a whole record shape is a type rather than a value. These building blocks carry that information. A macro writes almost all of them for you, so you meet them when you read generated code or when a wiring mistake reports a deeply nested type. This section exists to make such a type readable.

One idea runs through nearly all of them: a type can carry information the program never stores as a value. A struct can name a type parameter without keeping a field of that type, so a name, a number, or a lifetime becomes part of the type's identity, and the compiler matches on it during trait resolution. PhantomData is the standard-library marker that makes this legal. It comes first here, because the other types build on it.

The building blocks are either markers or recursive type-level lists.

Each marker attaches one piece of information at the type level. Index turns a tuple-field position into a type, in the same way that Symbol! turns a field name into one. Life lifts a lifetime into a type, so that it can pass through machinery that accepts only types. Field uses such a tag: it pairs a value with its type-level name, so a record entry or a variant entry carries its own name.

The recursive type-level lists are the chains that every structural shape is built from. Each list pairs a head-and-tail cell with a terminator, and generic code takes the list apart one element at a time. Each family covers one job, and the head cell's page carries the full account of that family. Cons and Nil build a record, and the Cons page explains the type-level product. Either and Void build a variant, and the Either page explains the type-level sum. Chars builds a string, and PathCons builds a routing path. You write these lists through the macros (Product!, Sum!, Symbol!, and Path!) and read them in expansions and errors.

MRef is the one type here that is not a building block. It is an ordinary runtime value, the owned-or-borrowed return type of a getter. It belongs in this section because it is a type rather than a trait or a provider, and you name it yourself as a getter's return type.

The ideas behind them​


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.