[Verse 1] In Rust there's a rule that keeps code running clean Every piece of data has an owner on the scene When you make a variable and give it some value That variable owns the data, it's simple and it's true [Chorus] One owner at a time, that's the golden rule Memory stays safe when we use this tool When the owner goes away, the data disappears No more memory leaks or programmer fears One owner at a time, Rust keeps it clear [Verse 2] Let's say you have a string stored inside variable one If you try to give it to another, the first one is done The ownership has moved now, transferred to the new The original can't use it, that access is through [Chorus] One owner at a time, that's the golden rule Memory stays safe when we use this tool When the owner goes away, the data disappears No more memory leaks or programmer fears One owner at a time, Rust keeps it clear [Bridge] Some types can be copied, like numbers small and light But strings and bigger structures follow ownership's might The borrow checker watches, making sure you play it right No dangling pointers hiding in your code tonight [Verse 3] When a function gets called and you pass data in The function becomes owner, that's how ownership begins Unless you borrow instead with an ampersand sign Then the original keeps it, everything's fine [Chorus] One owner at a time, that's the golden rule Memory stays safe when we use this tool When the owner goes away, the data disappears No more memory leaks or programmer fears One owner at a time, Rust keeps it clear [Outro] Ownership in Rust makes your programs shine One owner at a time, by design
← Functions and control flow | Move semantics (the mechanics) →