Rust

Ownership & Borrowing

Ownership rules, move semantics, borrowing (&T, &mut T), lifetimes, dangling references

22 питань зі співбесід·
Junior
1

What is ownership in Rust?

Відповідь

Ownership is a fundamental system in Rust that guarantees memory safety without a garbage collector. Each value has a single owner, and memory is automatically freed when the owner goes out of scope. This system prevents data races and use-after-free errors at compile time.

2

How many owners can a value have in Rust?

Відповідь

In Rust, a value can only have one owner at a time. This is the first rule of ownership. When ownership is transferred (move), the previous owner can no longer access the value. This rule ensures that no two parts of the code can modify or free the same memory.

3

What happens when a variable goes out of scope in Rust?

Відповідь

When a variable goes out of scope, Rust automatically calls the drop function which frees the memory. This behavior is deterministic and predictable, unlike garbage collectors that free memory non-deterministically. This pattern is called RAII (Resource Acquisition Is Initialization).

4

What is a move in Rust?

5

Which types implement the Copy trait in Rust?

+19 питань зі співбесід

Опануй Rust для наступної співбесіди

Отримай доступ до всіх питань, flashcards, технічних тестів, вправ code review та симуляторів співбесід.

Почни безкоштовно