Rust (language) Flashcards

1
Q

What is Rust primarily known for in terms of programming language design?

A

Rust is known for safety, performance, and concurrency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which system does Rust use to manage memory safely without a garbage collector?

A

Rust uses an ownership system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does Rust prevent common bugs like dangling pointers and double frees?

A

Rust enforces memory safety at compile time using ownership rules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the two types of borrowing in Rust?

A

Immutable borrowing and mutable borrowing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Fill in the blank: Rust allows either _______ or _______ borrowing, but not both at the same time.

A

immutable, mutable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a key advantage of Rust’s memory model compared to garbage-collected languages?

A

Rust provides memory safety without a garbage collector, improving performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does Rust ensure memory is deallocated safely?

A

Memory is deallocated automatically when data goes out of scope, using Rust’s ownership system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does Rust’s concept of ‘lifetimes’ prevent?

A

Lifetimes prevent references to data that has already been deallocated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are zero-cost abstractions in Rust?

A

Abstractions that have no runtime cost, allowing high-level constructs without performance penalties.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why is Rust’s performance comparable to C or C++?

A

Rust compiles directly to machine code, without an interpreter or virtual machine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does Rust handle concurrent access to data safely?

A

Rust uses ownership and borrowing rules to prevent data races at compile time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does Rust enable safe concurrency?

A

Rust enforces strict rules on data access and modification across threads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What feature does Rust include to facilitate multithreading and safe communication between threads?

A

Channels for message-passing concurrency and built-in multithreading support.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Fill in the blank: Rust’s ______ and _______ allow threads to communicate safely without sharing memory directly.

A

channels, threads

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is Cargo in Rust?

A

Cargo is Rust’s package manager and build system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are two key tools in Rust for code quality and formatting?

A

Clippy (linting tool) and Rustfmt (code formatter).

17
Q

How does Rust handle missing values without null pointers?

A

Rust uses the Option type to represent values that may be missing.

18
Q

What type in Rust is used to represent potential errors in a safe way?

A

The Result type.

19
Q

Fill in the blank: Rust’s type system uses ______ and ________ to enforce explicit error handling and avoid null pointers.

A

Option, Result

20
Q

How does Rust prevent runtime errors commonly associated with unhandled null values?

A

Rust requires explicit handling using Option and Result types.

21
Q

What is a primary benefit of Rust’s strong type system?

A

It enables safe and clear code with features like enums, pattern matching, and type inference.

22
Q

Why is Rust popular for WebAssembly (Wasm) projects?

A

Rust’s performance and safety features make it suitable for high-performance applications in the browser.

23
Q

What is Rust’s cross-platform capability useful for?

A

Running on multiple platforms, including Windows, macOS, Linux, and some support for embedded systems.

24
Q

Which companies have adopted Rust for its safety and performance features?

A

Microsoft, Amazon, Google, and the Linux kernel community.

25
Q

Fill in the blank: Rust’s package repository is called _______.

A

crates.io

26
Q

What does Rustdoc do?

A

Rustdoc generates documentation from source code comments and annotations.

27
Q

How does Rust support documentation creation and maintenance?

A

With Rustdoc, which creates HTML documentation directly from source files.

28
Q

What challenge might beginners face when learning Rust?

A

Rust has a steeper learning curve due to strict ownership and borrowing rules.

29
Q

What is a trade-off of Rust’s compile-time checks for safety?

A

Rust has longer compilation times for large projects.

30
Q

Why might some developers consider Rust’s slower compile times worth it?

A

The compile-time checks reduce runtime errors, improving code safety.