diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-08-30 23:46:38 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-08-30 23:46:38 -0700 |
| commit | c6fd2d31eeb871ad6baeb7888bc50347286d466d (patch) | |
| tree | 5a07b20ab3105a4a319aeca7ac06b563fe27d5d7 /src | |
| parent | f7f8b2096109d21a3bb1b150066ee57ba571f826 (diff) | |
| parent | ea888edf631d82f4a8fcdcc83c85ddb5e2b9cef4 (diff) | |
| download | rust-c6fd2d31eeb871ad6baeb7888bc50347286d466d.tar.gz rust-c6fd2d31eeb871ad6baeb7888bc50347286d466d.zip | |
rollup merge of #16807 : nham/guide_added_ownership_rule
Diffstat (limited to 'src')
| -rw-r--r-- | src/doc/guide.md | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/doc/guide.md b/src/doc/guide.md index 66db46aff8e..ba5ac0921ed 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -3668,15 +3668,20 @@ because it's easy. And if you need precise control over when something is deallocated, leaving it up to your runtime can make this difficult. Rust chooses a different path, and that path is called **ownership**. Any -binding that creates a resource is the **owner** of that resource. Being an -owner gives you three privileges, with two restrictions: +binding that creates a resource is the **owner** of that resource. + +Being an owner affords you some privileges: 1. You control when that resource is deallocated. 2. You may lend that resource, immutably, to as many borrowers as you'd like. -3. You may lend that resource, mutably, to a single borrower. **BUT** -4. Once you've done so, you may not also lend it out otherwise, mutably or - immutably. -5. You may not lend it out mutably if you're currently lending it to someone. +3. You may lend that resource, mutably, to a single borrower. + +But it also comes with some restrictions: + +1. If someone is borrowing your resource (either mutably or immutably), you may + not mutate the resource or mutably lend it to someone. +2. If someone is mutably borrowing your resource, you may not lend it out at + all (mutably or immutably) or access it in any way. What's up with all this 'lending' and 'borrowing'? When you allocate memory, you get a pointer to that memory. This pointer allows you to manipulate said |
