A Beginner’s Guide to Rust

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/17

flashcard set

Earn XP

Description and Tags

from “A Half-Hour to Learn Rust”

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

18 Terms

1
New cards

What makes Rust different from other system languages like C/C++?

Rust focuses on memory safety and concurrency without needing a garbage collector.

2
New cards

Are variables immutable or mutable by default in Rust?

Immutable by default. Use mut to make them mutable. This design choice minimizes bugs related to unintended variable changes.

3
New cards

What does the let keyword do in Rust?

It declares a variable, which is immutable unless mut is added.

4
New cards

What is the purpose of the match keyword in Rust?

It allows pattern matching, similar to a powerful switch-case statement.

5
New cards

What's the difference between struct and enum in Rust?

struct groups related fields into a type

enum defines a type with multiple possible variants

6
New cards

How do you define a function in Rust?

Using fn.

Example: fn add(a: i32, b: i32) -> i32 { a + b }

7
New cards

What does impl do in Rust?

It defines methods for a struct or enum.

8
New cards

What is ownership in Rust?

A memory model where each value has one owner; when ownership is transferred, the original variable is no longer valid.

9
New cards

What is borrowing in Rust?

Letting a function access a variable via a reference (&) without taking ownership.

10
New cards

What is mutable borrowing?

A reference (&mut) that allows modifying the borrowed data, but only one mutable borrow is allowed at a time.

11
New cards

How do vectors (Vec) work in Rust?

They are growable arrays. You can push, pop, and iterate over them.

12
New cards

How does error handling work in Rust?

Via Result<T, E> for recoverable errors and panic!() for unrecoverable ones.

13
New cards

What is the Option<T> type in Rust?

A type that either contains Some(value) or None, avoiding nulls.

14
New cards

How do you match on a Result type?

Using match to handle Ok(value) and Err(error) branches.

15
New cards

What is a trait in Rust?

A collection of methods that types can implement (similar to interfaces in other languages).

16
New cards

What are lifetimes in Rust?

Annotations that tell the compiler how long references should be valid.

17
New cards

How do you write a unit test in Rust?

Use #[test] before the test function and use assert_eq!() to check values

18
New cards

What is the Rust compiler’s biggest strength for beginners?

It gives detailed, helpful error messages, especially around ownership and types.