Search⌘ K
AI Features

Structs

Explore how to define and use structs in Rust, including regular, tuple, and unit-like structs. Understand instantiation with the new method and builder patterns to efficiently organize and manage data.

Structs are the foundation of dealing with data in Rust. Let’s do a quick review of the basics before we dive in deeper.

A quick review of structs

A structure is a named collection, defining a new type. A struct can take one of three forms.

  1. Regular structs:
struct Person {
    name: String,
    age: i8,
}
...