{
  "$type": "site.standard.document",
  "canonicalUrl": "https://deterministic.space/rust-ownership-and-borrowing-in-150-words.html",
  "path": "/rust-ownership-and-borrowing-in-150-words.html",
  "publishedAt": "2016-08-02T00:00:00.000Z",
  "site": "at://did:plc:x67qh7v3fd7znbdhauc45ng3/site.standard.publication/3mjcd2t6afe25",
  "textContent": "Recently, I wrote on reddit that a Rust book won't become obsolete in the next years if it focused on explaining concepts instead of current APIs. At basically the same time, I tried to explain some of Rust's concepts to a friend. I think I came up with a quite concise description (maybe even explanation) of \"ownership and borrowing\" (the concept that differentiates Rust from most other programming language).\n\n- - -\n\nOwnership: You own a resource, and when you are done with it, that resource is no longer in scope and gets deallocated.\n\nReferences to a resource depend on the lifetime of that resource (i.e., they are only valid until the resource is deallocated).\n\nMove semantics means: Giving an owned resource to a function means _giving it away_. You can no longer access it.\n\nTo _not_ move a resource, you instead use borrowing: You create a reference to it and move _that_. When you create a reference, you own that reference. Then you move it (and ownership of it) to the function you call. (Nothing new, just both concepts at the same time.)\n\nTo manipulate a resource without giving up ownership, you can create one mutable reference. During the lifetime of this reference, no other references to the same resource can exist.\n\nThat's it. And it's all checked at compile-time.",
  "title": "Rust's ownership and borrowing in 150 words",
  "updatedAt": "2016-08-02T00:00:00.000Z"
}