Conceptual
Login

Associated Types and Associated Constants

A trait can require that each implementing type name a related type or fix a constant value, not just supply functions. That lets a trait say "whoever implements me must declare what kind of data they work with, and what their name is" and have the compiler check it. It keeps configuration in the type system instead of in run-time settings.

Questions this Concept answers

  • Why do kernel driver traits express the table of matching hardware IDs as an associated constant rather than a field set while running?