diff options
| author | nham <hamann.nick@gmail.com> | 2014-08-27 20:02:59 -0400 |
|---|---|---|
| committer | nham <hamann.nick@gmail.com> | 2014-08-30 17:22:29 -0400 |
| commit | ea888edf631d82f4a8fcdcc83c85ddb5e2b9cef4 (patch) | |
| tree | a64b7fd6851eebfccb82be50eb1ec371da25bed1 | |
| parent | 0d3bd7720c50e3ada4bac77331d43926493be4fe (diff) | |
| download | rust-ea888edf631d82f4a8fcdcc83c85ddb5e2b9cef4.tar.gz rust-ea888edf631d82f4a8fcdcc83c85ddb5e2b9cef4.zip | |
doc: Add another restriction to the list of ownership rules.
| -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 8a634a083e8..5dedcde214c 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 |
