Merge pull request #113 from kumakichi/master

change structure of chapter 'interior mutability'
pull/116/head
Dhghomon 3 years ago committed by GitHub
commit ad61879cd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7477,7 +7477,7 @@ fn main() {
Another type you can use is `RefCell`.
## RefCell
### RefCell
A `RefCell` is another way to change values without needing to declare `mut`. It means "reference cell", and is like a `Cell` but uses references instead of copies.
@ -7572,7 +7572,7 @@ error: process didn't exit successfully: `target\debug\rust_book.exe` (exit code
`already borrowed: BorrowMutError` is the important part. So when you use a `RefCell`, it is good to compile **and** run to check.
## Mutex
### Mutex
`Mutex` is another way to change values without declaring `mut`. Mutex means `mutual exclusion`, which means "only one at a time". This is why a `Mutex` is safe, because it only lets one process change it at a time. To do this, it uses `.lock()`. `Lock` is like locking a door from the inside. You go into a room, lock the door, and now you can change things inside the room. Nobody else can come in and stop you, because you locked the door.
@ -7697,7 +7697,7 @@ fn main() {
}
```
## RwLock
### RwLock
`RwLock` means "read write lock". It is like a `Mutex` but also like a `RefCell`. You use `.write().unwrap()` instead of `.lock().unwrap()` to change it. But you can also use `.read().unwrap()` to get read access. It is like `RefCell` because it follows the rules:

Loading…
Cancel
Save