Rust advanced types: newtypes, type aliases, and the never type
Answer: The Rust type system has some features mentioned earlier but not yet discussed: newtypes, type aliases, the ! type, and dynamically sized types.
Newtypes and type aliases
The discussion starts with newtypes and why they are useful as types, then turns to type aliases, which are similar but have slightly different semantics.
Beyond earlier examples, the newtype pattern can statically keep values from being mixed up and can mark the units of a value.
Listing 20-16 wrapped u32 values in Millimeters and Meters for that reason.
The pattern is a lightweight way to hide implementation details, as discussed with encapsulation in Chapter 18.
A type alias, declared with the type keyword, gives an existing type another name.
Aliases do not add the type-checking benefits of a newtype: mixing Kilometers and i32 will not produce a compiler error.
The main use case for type synonyms is to reduce repetition. Type aliases are also commonly used with the Result<T, E> type for reducing repetition.
The never type
Rust also has a special type named !.
In type theory this is the empty type, because it has no values.
The book prefers the name never type, because it is used as the return type of a function that will never return.
The chapter also discusses dynamically sized types after this section.
See also
Claims
- id: C1 claim: Type aliases do not catch mixed units the way a newtype does. source: S1 evidence: "we don't get the type-checking benefits that we get from the newtype pattern"
- id: C2 claim: The usual reason to write a type synonym is to avoid repetition. source: S2 evidence: "The main use case for type synonyms is to reduce repetition."
- id: C3 claim: The ! type is used when a function never returns. source: S1 evidence: "We prefer to call it the never type"
Sources
- [S1] Advanced Types - The Rust Programming Language. The Rust Project Developers. https://doc.rust-lang.org/book/ch20-03-advanced-types.html . License: MIT OR Apache-2.0. Accessed 2026-11-26.
- [S2] Advanced Types (source). The Rust Project Developers. https://raw.githubusercontent.com/rust-lang/book/main/src/ch20-03-advanced-types.md . License: MIT OR Apache-2.0. Accessed 2026-11-26.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Project Developers, Advanced Types - The Rust Programming Language; The Rust Project Developers, Advanced Types (source). MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Rust Project Developers, Advanced Types - The Rust Programming Language; The Rust Project Developers, Advanced Types (source). MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers.
Cite this
iinventedlight. 2026. "Rust advanced types: newtypes, type aliases, and the never type." iinventedlight Library, iil:note:3e6fxvnz, version of 2026-11-26. https://iinventedlight.com/library/notes/rust-advanced-types/. License: CC-BY-4.0.
@misc{iil_note_3e6fxvnz,
author = {{iinventedlight}},
title = {{Rust advanced types: newtypes, type aliases, and the never type}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/rust-advanced-types/},
note = {Permanent ID iil:note:3e6fxvnz. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- rust-advanced-types.schema.json (schema; CC-BY-4.0)
- rust-advanced-types.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-advanced-types.md.