---
source: https://iinventedlight.com/library/notes/rust-structs.md
title: "Defining and instantiating structs in Rust"
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; https://github.com/rust-lang/book/blob/main/LICENSE-MIT); MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT); prose restates or closely paraphrases cited source lines"
license_family: rust-mit
rule_check: "needs rule check (family not in auto-publish rule; check.mjs auto-approves only usgov and arxiv-ccby)"
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Defining and Instantiating Structs - The Rust Programming Language, MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT); Rust by Example, Structures - Rust By Example, MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Rust"
tags: ['rust', 'structs', 'types']
sources:
  - id: S1
    title: "Defining and Instantiating Structs - The Rust Programming Language"
    publisher: The Rust Programming Language
    url: https://doc.rust-lang.org/book/ch05-01-defining-structs.html
    accessed: 2026-11-04
    license: "MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT)"
  - id: S2
    title: "Structures - Rust By Example"
    publisher: Rust by Example
    url: https://doc.rust-lang.org/rust-by-example/custom_types/structs.html
    accessed: 2026-11-04
    license: "MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT)"
---
# Defining and instantiating structs in Rust

**Answer:** Structs are similar to tuples in that both hold multiple related values, and like tuples, the pieces of a struct can be different types. Unlike with tuples, in a struct you'll name each piece of data so it's clear what the values mean. (S1)

## Defining one

- Structs are more flexible than tuples: You don't have to rely on the order of the data to specify or access the values of an instance. (S1)
- To define a struct, we enter the keyword struct and name the entire struct. (S1)
- A struct's name should describe the significance of the pieces of data being grouped together. (S1)
- Inside curly brackets, we define the names and types of the pieces of data, which we call fields. (S1)

## Three kinds

- Tuple structs, which are, basically, named tuples. (S2)
- The classic C structs. (S2)
- Unit structs, which are field-less, are useful for generics. (S2)

## Claims
- id: C1
  claim: Struct fields are named.
  source: S1
  evidence: "you’ll name each piece of data so it’s clear what the values mean."
- id: C2
  claim: Fields are named data pieces in braces.
  source: S1
  evidence: "which we call fields."
- id: C3
  claim: Tuple structs are named tuples.
  source: S2
  evidence: "Tuple structs, which are, basically, named tuples."
- id: C4
  claim: Unit structs are field-less.
  source: S2
  evidence: "Unit structs, which are field-less, are useful for generics."

## Sources
- [S1] Defining and Instantiating Structs - The Rust Programming Language. The Rust Programming Language. https://doc.rust-lang.org/book/ch05-01-defining-structs.html . License: MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT). Accessed 2026-11-04.
- [S2] Structures - Rust By Example. Rust by Example. https://doc.rust-lang.org/rust-by-example/custom_types/structs.html . License: MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
