← Back to AILP Home

Traits Cookbook

This subsection of the guide is a focused, example-driven reference for Nitpick's trait / impl / dyn surface as it stands at the close of the v0.31.1.x phase (Phase 2 of the v0.31.x cycle).

Traits in Nitpick are a static abstraction over behaviour: a trait declares a set of method signatures, an impl T:for:U block supplies those signatures for a concrete type U, and call sites dispatch in two modes — static (the type is known at compile time and the method is resolved directly) and dynamic (the value is held behind a dyn T fat pointer and the method is resolved through a vtable at run time).

Chapters

  1. Basics — declaring a trait, writing an impl T:for:U, and calling methods via UFCS (x.foo()).
  2. Dyn surfacedyn T as a local variable, struct field, and function parameter; how concrete → dyn coercion works.
  3. Borrow rules$$i dyn T and $$m dyn T borrows, the source-side conflict rules, and the call-site interaction.
  4. Return-borrow methods$$i / $$m return types, the from <ident> source-binding clause, the multi-borrow defaults (TRAIT-RET-DEC-002/005), and why dyn dispatch is rejected for return-borrow methods (ARIA-053). New in v0.31.8.x.

Each chapter is short and self-contained.

Conventions used in these chapters

Validation status (v0.31.1.10)

Scope and non-scope

In scope for Phase 2 / v0.31.1.x:

Not yet in scope (deferred to later v0.31.x phases or v0.32.x+):