liveBook · Manning

Associated type

An associated type is a type member declared by a trait or similar abstraction whose concrete type is specified by each implementation.

How 2 Manning books explain it

Learn Rust in a Month of Lunches

An associated type is a type declaration attached to a Rust trait whose concrete value is specified for each implementation.

How it is used
Uses associated types to connect trait behavior with implementation-specific result types in iterators, futures, and arithmetic.
How deep it goes
Defines the syntax and works through custom and standard traits, but defers deeper details of pinning and asynchronous internals.
Examples
Demonstrates Iterator::Item, Future::Output, Add::Output, and a ChangeForm trait implemented for String and i32.
What you can do after
Apply associated types by declaring them in traits and choosing concrete types when implementing those traits.

Read how Learn Rust in a Month of Lunches explains associated type →

Functional Design and Architecture: Examples in Haskell

An associated type is a type member declared within a type class or similar abstraction and determined by its implementing type.

How it is used
Uses associated types to connect entities with database-specific keys and values in a generic, type-safe persistence interface.
How deep it goes
Explains declarations, concrete instances, and generic use, while stopping short of a broader formal treatment of type-level programming.
Examples
Demonstrates MeteorEntity and CometEntity instances with distinct keys, stored values, conversions, and a generic loadEntity function.
What you can do after
Build it from scratch by declaring entity-specific associated types and implementing generic key, value, and conversion operations.

Read how Functional Design and Architecture: Examples in Haskell explains associated type →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.