← All notes

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

Three kinds

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · 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).

Cite this

Permanent ID: iil:note:p1z7yger

iinventedlight. 2026. "Defining and instantiating structs in Rust." iinventedlight Library, iil:note:p1z7yger, version of 2026-11-04. https://iinventedlight.com/library/notes/rust-structs/. License: CC-BY-4.0.

@misc{iil_note_p1z7yger,
  author = {{iinventedlight}},
  title = {{Defining and instantiating structs in Rust}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/rust-structs/},
  note = {Permanent ID iil:note:p1z7yger. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/rust-structs.md.