[{"id":"rustbeginner-001","courseId":"rust-beginner","domain":"ownership-and-borrowing","topic":"Ownership rules","prompt":"A teammate asks how Rust frees heap memory without a garbage collector and without the programmer calling free. Which description is correct?","hint":"Compare it with the two approaches most languages take.","explain":"Languages differ in who frees heap memory: a collector that runs during execution, or the programmer by hand. Rust takes a third route, so compare when its checks happen.","source":"https://doc.rust-lang.org/book/ch04-01-what-is-ownership.html","interaction":{"type":"single"},"options":[{"id":"a","text":"A set of ownership rules that the compiler checks","why":"Rust manages memory with ownership rules that the compiler checks; if a rule is broken, the program won't compile."},{"id":"b","text":"A garbage collector that periodically frees memory no longer in use","whyNot":"Some languages use a collector that runs during execution; Rust says it takes a third approach instead."},{"id":"c","text":"The programmer explicitly allocates and frees each block","whyNot":"In other languages the programmer must allocate and free memory explicitly; Rust doesn't require that."},{"id":"d","text":"Ownership checks that run during execution and slow the program down","whyNot":"Rust's ownership features don't slow the program down while it runs; the rules are checked before that."}],"answer":"a","explanation":"Rust manages heap memory through ownership rules that the compiler checks, with no garbage collector, no manual freeing, and no runtime slowdown from the rules.","concept":"Rust manages heap memory through ownership rules that the compiler checks, with no garbage collector, no manual freeing, and no runtime slowdown from the rules.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Rust's memory safety comes from rules the compiler checks, not from a collector."]},{"id":"rustbeginner-002","courseId":"rust-beginner","domain":"ownership-and-borrowing","topic":"Moves of heap data","prompt":"A variable s1 holds a String. A teammate writes the line below. Which description of what happens is correct?","hint":"Ask how many variables may own the same heap data at once.","explain":"A String keeps its text on the heap, and Rust tracks which variable owns that data. Consider what a plain assignment does to that ownership, and whether the heap data gets duplicated.","source":"https://doc.rust-lang.org/book/ch04-01-what-is-ownership.html","interaction":{"type":"single"},"options":[{"id":"a","text":"The String moves to s2, and s1 can no longer be used","why":"Assigning a value to another variable moves it, and the old variable is no longer valid."},{"id":"b","text":"The heap data is copied, so s1 and s2 each own their own String","whyNot":"Only the clone method makes a deep copy of heap data; plain assignment moves the value instead."},{"id":"c","text":"s2 becomes a reference to s1, so s1 still owns the data","whyNot":"Plain assignment doesn't create a reference; it transfers ownership to s2."},{"id":"d","text":"s1 is dropped right away and s2 holds an empty String","whyNot":"A moved-from variable isn't dropped at the assignment; its value now belongs to s2 and is freed with s2."}],"answer":"a","explanation":"Assigning a String to another variable moves it: the new variable owns the heap data and the old variable can no longer be used.","concept":"Assigning a String to another variable moves it: the new variable owns the heap data and the old variable can no longer be used.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"let s1 = String::from(\"hi\");\nlet s2 = s1;","takeaways":["After a String is assigned to a new variable, the old name stops being valid."]},{"id":"rustbeginner-003","courseId":"rust-beginner","domain":"ownership-and-borrowing","topic":"Deep copies with clone","prompt":"A teammate wants two independent String values with the same heap contents, so changing one never affects the other. Which call makes that copy?","hint":"Think about which operation does the extra work of copying the heap data.","explain":"Assignment and borrowing both give access without duplicating heap data. Making a separate copy of heap data is something you request explicitly in the code, and it can cost time.","source":"https://doc.rust-lang.org/book/ch04-01-what-is-ownership.html","interaction":{"type":"single"},"options":[{"id":"a","text":"s1.clone()","why":"clone deeply copies the String's heap data into a new, separate value."},{"id":"b","text":"let s2 = s1;","whyNot":"Plain assignment moves the String into s2, so s1 is no longer valid, and no heap data is copied."},{"id":"c","text":"let s2 = &s1;","whyNot":"A reference borrows s1 and creates no second owned String with its own data."},{"id":"d","text":"s1.len()","whyNot":"len() returns the length of the String as a number; it doesn't copy anything."}],"answer":"a","explanation":"The clone method deeply copies a String's heap data; assignment moves it, a reference borrows it, and len only reads the length.","concept":"The clone method deeply copies a String's heap data; assignment moves it, a reference borrows it, and len only reads the length.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Calling clone on a String duplicates its heap data, so it costs time."]},{"id":"rustbeginner-004","courseId":"rust-beginner","domain":"ownership-and-borrowing","topic":"Copy types on assignment","prompt":"Because tuples implement Copy, assigning a value of type (i32, String) to another variable leaves the original usable.","hint":"Check every element of the tuple, not only the integer.","explain":"Copy applies to a type only when its values are simple stack-only data. A compound type can only be Copy if every one of its parts is.","source":"https://doc.rust-lang.org/book/ch04-01-what-is-ownership.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"Tuples are Copy only when every element is Copy, and String is not."},{"id":"b","text":"False","why":"(i32, String) does not implement Copy, so assigning it moves the tuple and the original can't be used."}],"answer":"b","explanation":"A tuple implements Copy only if every element does: (i32, i32) is Copy, but (i32, String) is not.","concept":"A tuple implements Copy only if every element does: (i32, i32) is Copy, but (i32, String) is not.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["A compound type is Copy only if all of its parts are Copy."]},{"id":"rustbeginner-005","courseId":"rust-beginner","domain":"ownership-and-borrowing","topic":"Ownership passed to functions","prompt":"main passes a String to takes_ownership and then tries to use it. Which TWO statements are true?","hint":"Think about what the variable in main is allowed to do after the value is passed.","explain":"Passing a value to a function works like assignment: it moves or is copied, depending on the type. Trace who owns the data during the call and who frees it.","source":"https://doc.rust-lang.org/book/ch04-01-what-is-ownership.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"Using s after takes_ownership(s) is a compile-time error.","why":"Rust rejects use of a moved value at compile time, because s's value moved into the function."},{"id":"b","text":"The String's memory is freed when takes_ownership ends, not when main ends.","why":"The parameter goes out of scope at the end of takes_ownership, and drop frees the backing memory then."},{"id":"c","text":"takes_ownership receives a copy of s, so main can still use s.","whyNot":"A String doesn't implement Copy, so passing it moves the value rather than copying it."},{"id":"d","text":"Passing s to a function only borrows it, so main keeps ownership.","whyNot":"Passing a variable by value moves it; borrowing needs an & in both the call and the parameter."},{"id":"e","text":"Adding mut to s lets main use it after the call.","whyNot":"mut only allows the value to be changed; it does not stop the move."},{"id":"f","text":"An i32 passed to a function moves into it, just like the String.","whyNot":"i32 implements Copy, so passing it copies the value and the caller keeps using it."}],"answer":"ab","explanation":"Passing a non-Copy value like String to a function moves ownership into the parameter, which frees the value when the function ends.","concept":"Passing a non-Copy value like String to a function moves ownership into the parameter, which frees the value when the function ends.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"fn main() {\n    let s = String::from(\"hello\");\n    takes_ownership(s);\n    println!(\"{s}\");\n}\n\nfn takes_ownership(some_string: String) {\n    println!(\"{some_string}\");\n}","takeaways":["A String passed by value is freed at the end of the function that receives it."]}]