---
source: https://iinventedlight.com/library/notes/rust-slices.md
title: "Rust string slices and array slices"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT OR Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers); additional cited sources under MIT OR Apache-2.0; prose restates cited source lines in own words"
license_family: rust-mit
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Rust Project (The Rust Programming Language book), The Slice Type - The Rust Programming Language, MIT OR Apache-2.0; The Rust Standard Library, slice primitive type, MIT OR Apache-2.0. Notices: The Rust Programming Language book (rust-lang/book): Copyright (c) 2010 The Rust Project Developers; MIT OR Apache-2.0, used under MIT (https://github.com/rust-lang/book/blob/main/LICENSE-MIT). The Rust Standard Library docs (rust-lang/rust): Copyright (c) The Rust Project Contributors; MIT OR Apache-2.0, used under MIT (https://github.com/rust-lang/rust/blob/master/LICENSE-MIT)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-09
status: published
approved_by: "Cole Withington, 2026-11-09 13:40 PT: \"Yes, publish all 15 Rust drafts\""
checked_on: 2026-11-09
as_of: 2026-11-09
confidence: medium
untested: "No Rust code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-systems: Rust slices"
tags: [rust, slices, strings, ownership]
client: Librarian
sources:
  - id: S1
    title: "The Slice Type - The Rust Programming Language"
    publisher: The Rust Project (The Rust Programming Language book)
    url: https://doc.rust-lang.org/book/ch04-03-slices.html
    accessed: 2026-11-09
    license: "MIT OR Apache-2.0"
  - id: S2
    title: "slice primitive type"
    publisher: The Rust Standard Library
    url: https://doc.rust-lang.org/std/primitive.slice.html
    accessed: 2026-11-09
    license: "MIT OR Apache-2.0"
---
# Rust string slices and array slices

**Answer:** A slice is a kind of reference without ownership. Write string slices as `&str`. String literals stay immutable because `&str` is an immutable reference.

## Slices

You can reference a contiguous sequence of collection elements with a slice instead of the whole collection. A string slice refers to part of a `String`.

## Array slices

Array slices store a first-element reference plus a length, matching string slices. The `slice` type is a dynamically-sized view into a contiguous sequence.

## See also

- [rust-ownership-borrowing](https://iinventedlight.com/library/notes/rust-ownership-borrowing/)

## Claims

- id: C1
  claim: A slice is a kind of reference and does not have ownership.
  source: S1
  evidence: "A slice is a kind of reference, so it does not have ownership."
- id: C2
  claim: The type that signifies a string slice is written as &str.
  source: S1
  evidence: "The type that signifies \"string slice\" is written as &str: <Listing file-name=\"src/main.rs\"> rust </Listing> We"
- id: C3
  claim: String literals are immutable because &str is an immutable reference.
  source: S1
  evidence: "This is also why string literals are immutable; &str is an immutable reference."
- id: C4
  claim: A slice is a dynamically-sized view into a contiguous sequence.
  source: S2
  evidence: "A dynamically-sized view into a contiguous sequence, [T] ."

## Sources

- [S1] The Slice Type - The Rust Programming Language. The Rust Project (The Rust Programming Language book). https://doc.rust-lang.org/book/ch04-03-slices.html . License: MIT OR Apache-2.0. Accessed 2026-11-09.
- [S2] slice primitive type. The Rust Standard Library. https://doc.rust-lang.org/std/primitive.slice.html . License: MIT OR Apache-2.0. Accessed 2026-11-09.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources and notices: The Rust Programming Language book (rust-lang/book): Copyright (c) 2010 The Rust Project Developers; MIT OR Apache-2.0, used under MIT (https://github.com/rust-lang/book/blob/main/LICENSE-MIT). The Rust Standard Library docs (rust-lang/rust): Copyright (c) The Rust Project Contributors; MIT OR Apache-2.0, used under MIT (https://github.com/rust-lang/rust/blob/master/LICENSE-MIT). Text was condensed and changed from the originals.

---

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