
Understand it
Ownership determines which value is responsible for a resource. Moves transfer that responsibility; Copy types can be duplicated implicitly, while Clone is explicit. Normal scope exit drops owned values, but memory safety does not promise that every destructor runs: forgetting values, reference cycles or process termination can skip cleanup.
In an interview, anchor the answer to a short trace rather than a slogan. Create a String, pass it by value to a function, and ask whether the original binding can be used afterward. The owned string moves into the parameter; only the new owner may use it. If the function needs to read but not retain the string, accept &str instead. Small Copy values such as integers behave differently because an assignment copies their bits and leaves the original usable. Clone is an explicit request to duplicate a non-Copy value, potentially allocating.
Describe when cleanup happens. When an owned value leaves its scope, Drop runs deterministically unless ownership moved elsewhere. That gives clear resource management without a tracing garbage collector, but it does not mean every value lives on the stack. A String value contains metadata and points to owned heap bytes. Ownership is about who is responsible for that allocation, not a location label.
A strong answer ends with an example of a design choice. A read-only helper can borrow, a constructor may take ownership, and a shared long-lived value may need a different abstraction. If the interviewer asks about a compiler error, identify the exact move and later use. State what the function actually needs before choosing clone(). That demonstrates you can use ownership to shape an API rather than recite four rules.
A move does not necessarily copy the whole heap allocation. In the String example, it transfers the small handle and responsibility for the buffer. That distinction explains why moves are common and clones are explicit.
Interview follow-up: When would cloning be appropriate? Explain its semantic and allocation cost, then name a situation where cleanup can be intentionally skipped.
Read the code
let a = String::from("x");
let b = a; // move: a is unusable
let n = 5;
let m = n; // copy: n still usable
{
let _t = String::from("t");
} // dropped here, deterministicallyThree behaviours an interviewer is listening for.
Practice starter
fn take(_: String) {}
fn main() {
let s = String::from("x");
take(s);
println!("{s}"); // deliberate compile error
}Try it
Explain ownership in under a minute, out loud.
What success looks like: You name moves, Copy, and Drop without mentioning syntax first.
Check your understanding
Why is using s after take(s) rejected?
Reveal the answer
- Passing a String copies its buffer and leaves both owners usable.
- The by-value call transfers ownership of s into the parameter.
- The function signature creates a shared borrow lasting to main’s end.
String is not Copy. take consumes this value; borrow &str instead if the helper only needs to read it.
Go deeper
Common misconception: The function signature creates a shared borrow lasting to main’s end.
A by-value parameter borrows nothing. take(s) moves the String into the parameter, so the error is a use after move, not a borrow conflict.
- Identify the contract: Explaining ownership well means naming the guarantee, not the syntax.
- Trace the concrete example: Three behaviours an interviewer is listening for.
- Test the changed constraint: When would cloning be appropriate? Explain its semantic and allocation cost, then name a situation where cleanup can be intentionally skipped.
Transfer challenge: When would cloning be appropriate? Explain its semantic and allocation cost, then name a situation where cleanup can be intentionally skipped.
Connections
- Why Borrowing Works: Aliasing and mutation rules
Learn this lesson with AI
Paste this into Claude, Codex, Cursor or another agent connected to Crabrix Academy. It contains only this lesson’s public details.
I'm learning Rust with Crabrix Academy. Teach me this lesson with the Crabrix Academy tools. Lesson: Explain Ownership (courseId "interview", lessonId "q-ownership") Link: https://crabrix.com/learn/interview/q-ownership/ Goal: Ownership tracks resource responsibility; move, borrow and clone express different contracts. Practice: open the starter in the Crabrix Playground (https://crabrix.com/playground/?lesson=interview/q-ownership) and I will write the code there. Explain it step by step for my level, let me write the code myself, give hints before any solution, and do not mark anything as passed: only Crabrix checks do that.