← All notes

Rust tuples: fixed-length groups of mixed types

Answer: A tuple groups values with a variety of types into one compound type. Tuples have a fixed length. The tuple without any values has a special name, unit.

What a tuple is

A tuple groups values with a variety of types into one compound type.

The length is fixed: once you declare a tuple, it cannot grow or shrink in size.

Write a comma-separated list of values inside parentheses; each position may have a different type.

Destructuring and indexed access

A variable bound to a tuple holds the whole value, because a tuple is considered a single compound element.

In the book's three-element example, destructuring breaks the single tuple into three parts.

We can also access a tuple element with a period followed by its index.

The empty tuple is called unit. Both the value and the type are written ().

Mixed types and multiple return values

Rust by Example describes a tuple as a collection of values of different types.

Functions can use tuples to return multiple values.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Data Types; Rust by Example, tuples. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/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 Programming Language, Data Types; Rust by Example, tuples. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers.

Cite this

Permanent ID: iil:note:yxknn1n3

iinventedlight. 2026. "Rust tuples: fixed-length groups of mixed types." iinventedlight Library, iil:note:yxknn1n3, version of 2026-11-23. https://iinventedlight.com/library/notes/rust-tuples/. License: CC-BY-4.0.

@misc{iil_note_yxknn1n3,
  author = {{iinventedlight}},
  title = {{Rust tuples: fixed-length groups of mixed types}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/rust-tuples/},
  note = {Permanent ID iil:note:yxknn1n3. License: CC-BY-4.0.},
}

Markdown

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.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-tuples.md.