---
source: https://iinventedlight.com/library/notes/rust-arrays.md
title: "Rust arrays: fixed-length collections of one type"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT OR Apache-2.0 (Rust by Example); MIT OR Apache-2.0 (The Rust Programming Language); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Rust by Example, Arrays and Slices; The Rust Programming Language, Data Types. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: rust-arrays"
tags: [rust, arrays, slices, data-types]
client: Librarian
sources:
  - id: S1
    title: "Arrays and Slices"
    publisher: Rust by Example
    url: https://doc.rust-lang.org/rust-by-example/primitives/array.html
    accessed: 2026-11-23
    license: "MIT OR Apache-2.0"
  - id: S2
    title: "Data Types"
    publisher: The Rust Programming Language
    url: https://doc.rust-lang.org/book/ch03-02-data-types.html
    accessed: 2026-11-23
    license: "MIT OR Apache-2.0"
---
# Rust arrays: fixed-length collections of one type
**Answer:** Stored in contiguous memory, an array collects objects of the same type T. Compile-time length is part of the type, written [T; length]. In Rust that length is fixed.

## Type signature and memory

Values of one type T sit in contiguous memory when stored in an array.

Write an array with brackets []. The type signature [T; length] carries the compile-time length.

A slice looks similar, yet its length is not known at compile time.

The slice value is a two-word object: a pointer to the data, then the length.

## Fixed length, stack, and access

Tuples and arrays are Rust's two primitive compound types.

Every element of an array must have the same type, which is unlike a tuple.

The length is fixed, which is unlike arrays in some other languages.

An array isn't as flexible as the vector type. If you're unsure which type fits, chances are you should use a vector.

Choose an array when the number of elements will not need to change.

After the semicolon, the example uses 5 to show five elements.

An array is one chunk of memory with a known, fixed size. It can be allocated on the stack.

Index access is allowed. An index past the end of the array is invalid.

## See also

- [rust-tuples](https://iinventedlight.com/library/notes/rust-tuples/)
- [rust-slices](https://iinventedlight.com/library/notes/rust-slices/)
- [rust-vectors](https://iinventedlight.com/library/notes/rust-vectors/)

## Claims

- id: C1
  claim: Every element of an array must have the same type.
  source: S2
  evidence: "every element of an array must have the same type"

- id: C2
  claim: Arrays in Rust have a fixed length.
  source: S2
  evidence: "arrays in Rust have a fixed length"

- id: C3
  claim: Length is part of the type signature [T; length].
  source: S1
  evidence: "type signature [T; length]"

- id: C4
  claim: An array can be allocated on the stack.
  source: S2
  evidence: "can be allocated on the stack"

- id: C5
  claim: A slice's length is not known at compile time.
  source: S1
  evidence: "their length is not known at compile time"

## Sources

- [S1] Arrays and Slices. Rust by Example. https://doc.rust-lang.org/rust-by-example/primitives/array.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.

- [S2] Data Types. The Rust Programming Language. https://doc.rust-lang.org/book/ch03-02-data-types.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.

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

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
