[Verse 1] In Rust there's a rule that keeps memory clean One owner at a time for each value you've seen But sometimes you need to just peek and not take That's when borrowing helps for your program's sake You use an ampersand to create a reference No ownership transfer just temporary preference [Chorus] One at a time for mutable borrow Shared or exclusive that's the rule to follow References can't outlive what they point to Borrowing rules keep your memory true Check it at compile time before you run Rust prevents the races before they've begun [Verse 2] Immutable borrows you can have many more Read-only access opening that door But mutable borrows are exclusive you see Only one at a time is the guarantee No mixing the two at the very same time This prevents data races by Rust's design [Chorus] One at a time for mutable borrow Shared or exclusive that's the rule to follow References can't outlive what they point to Borrowing rules keep your memory true Check it at compile time before you run Rust prevents the races before they've begun [Bridge] The borrow checker is watching your code Making sure lifetimes follow the right road When the owner goes away references must too No dangling pointers coming through It might seem strict but it's keeping you safe From bugs that in other languages you'd chase [Verse 3] Sometimes you'll fight with the borrow checker's might But trust in the process it's keeping things right Split your borrows or clone when you need These patterns will help you succeed The compiler's your friend though it might not feel so It's teaching you safety as your skills grow [Final Chorus] One at a time for mutable borrow Shared or exclusive that's the rule to follow References can't outlive what they point to Borrowing rules keep your memory true Check it at compile time before you run Rust prevents the races before they've begun [Outro] Borrow with care and your code will be strong The checker's protection will guide you along
← Move semantics (the mechanics) | Error handling with the question mark operator →