skip to content

Ownership and Borrowing

Every value has one owner, a move transfers it, and a borrow lends it under rules the compiler checks. Interviewers start here because nothing else in Rust makes sense without it.

on this pageshow

explore

questions

page 2 of 2

A Rust pool guard must hand its connection back inside Drop and also offer `detach(self)`; why does moving `self.conn` out fail in both, and how do you fix it?

level: seniorimportance: nice to knowfreq 22%

basics

~20 s

Drop::drop gets &mut self, so moving a field out is E0507; a by-value method on a Drop type cannot move a field out either (E0509), since drop still needs the whole value. Store Option<Connection> and take() it, or use ManuallyDrop with unsafe take.

open as a page

showing 31–31 of 31