Skip to content

Commit ea888ed

Browse files
committed
doc: Add another restriction to the list of ownership rules.
1 parent 0d3bd77 commit ea888ed

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/doc/guide.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3668,15 +3668,20 @@ because it's easy. And if you need precise control over when something is
36683668
deallocated, leaving it up to your runtime can make this difficult.
36693669

36703670
Rust chooses a different path, and that path is called **ownership**. Any
3671-
binding that creates a resource is the **owner** of that resource. Being an
3672-
owner gives you three privileges, with two restrictions:
3671+
binding that creates a resource is the **owner** of that resource.
3672+
3673+
Being an owner affords you some privileges:
36733674

36743675
1. You control when that resource is deallocated.
36753676
2. You may lend that resource, immutably, to as many borrowers as you'd like.
3676-
3. You may lend that resource, mutably, to a single borrower. **BUT**
3677-
4. Once you've done so, you may not also lend it out otherwise, mutably or
3678-
immutably.
3679-
5. You may not lend it out mutably if you're currently lending it to someone.
3677+
3. You may lend that resource, mutably, to a single borrower.
3678+
3679+
But it also comes with some restrictions:
3680+
3681+
1. If someone is borrowing your resource (either mutably or immutably), you may
3682+
not mutate the resource or mutably lend it to someone.
3683+
2. If someone is mutably borrowing your resource, you may not lend it out at
3684+
all (mutably or immutably) or access it in any way.
36803685

36813686
What's up with all this 'lending' and 'borrowing'? When you allocate memory,
36823687
you get a pointer to that memory. This pointer allows you to manipulate said

0 commit comments

Comments
 (0)