Rust Structs, Enums, Match and Box

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/13

flashcard set

Earn XP

Description and Tags

Flashcards covering structs, enums, match statements, and Box<T> in Rust.

Last updated 9:03 AM on 6/6/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

14 Terms

1
New cards

Struct

A complex type defined by the user that can contain any number of fields of any type.

2
New cards

Instantiating a struct

Can be done primitively by instantiating all of its fields.

3
New cards

Tuple Structs

Useful for naming and differentiating one tuple from others, especially when naming each field in a regular struct would be verbose or redundant.

4
New cards

Struct Methods

Functions defined within the context of a struct using 'impl'. They can take '&self' (immutable reference), '&mut self' (mutable reference), or 'self' (ownership) as arguments.

5
New cards

Static Functions in Structs

Often used for constructors that return a new instance of the struct. 'Self' is an alias for the type in the 'impl' block.

6
New cards

Enum

Used for saying a value is one of a possible set of values (enumeration constants).

7
New cards

Enums with data

Group the data right next to the type.

8
New cards

Box

A smart pointer that stores data on the heap, allowing for enums with recursive types to have a known size at compile time.

9
New cards

Option

Rust’s solution for null checks. An enum that holds Some(T) or None, helping the user with checking of possibly non-existent data.

10
New cards

Option API shortcuts

unwrap() extracts the value in Some, crashing if None; expect("str") does the same but prints an error message; isok() returns true if Some; isnone() returns true if None.

11
New cards

Match Statement

Used to compare a value against a series of patterns and execute code based on the matching pattern. Must be exhaustive to avoid errors.

12
New cards

Catch-all statements in Match

'other' catches the value from a match statement. '_' matches the pattern

13
New cards

Matching with if statement

Allows for additional conditions to be checked within a match arm.

14
New cards

If let shorthand

A concise way to run code when a value matches a single pattern, particularly useful with Options.

Explore top notes

note
MCB_410
Updated 369d ago
0.0(0)
note
Chapter Three: The Social Self
Updated 1144d ago
0.0(0)
note
Resistance and V=IR
Updated 1270d ago
0.0(0)
note
Irregular -oir Verbs
Updated 1248d ago
0.0(0)
note
Animal Farm Test
Updated 1256d ago
0.0(0)
note
MCB_410
Updated 369d ago
0.0(0)
note
Chapter Three: The Social Self
Updated 1144d ago
0.0(0)
note
Resistance and V=IR
Updated 1270d ago
0.0(0)
note
Irregular -oir Verbs
Updated 1248d ago
0.0(0)
note
Animal Farm Test
Updated 1256d ago
0.0(0)

Explore top flashcards

flashcards
Week 3 : Deviance Crime and Law
41
Updated 563d ago
0.0(0)
flashcards
Asi Se Dice Level 3: Chapter 3
77
Updated 1243d ago
0.0(0)
flashcards
Wanted: A Just Right Government
28
Updated 1187d ago
0.0(0)
flashcards
Ser Adjectives
38
Updated 1158d ago
0.0(0)
flashcards
UX-Study
131
Updated 1028d ago
0.0(0)
flashcards
Semester 2 Vocab
120
Updated 1160d ago
0.0(0)
flashcards
Duits woordenschat hobbies
36
Updated 1130d ago
0.0(0)
flashcards
Week 3 : Deviance Crime and Law
41
Updated 563d ago
0.0(0)
flashcards
Asi Se Dice Level 3: Chapter 3
77
Updated 1243d ago
0.0(0)
flashcards
Wanted: A Just Right Government
28
Updated 1187d ago
0.0(0)
flashcards
Ser Adjectives
38
Updated 1158d ago
0.0(0)
flashcards
UX-Study
131
Updated 1028d ago
0.0(0)
flashcards
Semester 2 Vocab
120
Updated 1160d ago
0.0(0)
flashcards
Duits woordenschat hobbies
36
Updated 1130d ago
0.0(0)