Merge pull request #100 from chapeupreto/fix-struct-name

use CityData instead of Cities for the name of the struct
This commit is contained in:
Dhghomon 2021-01-01 14:58:09 +09:00 committed by GitHub
commit f5b59c27f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8142,7 +8142,7 @@ fn main() {
After `takes_a_string` takes `user_name`, you can't use it anymore. Here that is no problem: you can just give it `user_name.clone()`. But sometimes a variable is part of a struct, and maybe you can't clone the struct. Or maybe the `String` is really long and you don't want to clone it. These are some reasons for `Rc`, which lets you have more than one owner. An `Rc` is like a good office worker: `Rc` writes down who has ownership, and how many. Then once the number of owners goes down to 0, the variable can disappear.
Here's how you use an `Rc`. First imagine two structs: one called `City`, and another called `Cities`. `City` has information for one city, and `Cities` puts all the cities together in `Vec`s.
Here's how you use an `Rc`. First imagine two structs: one called `City`, and another called `CityData`. `City` has information for one city, and `CityData` puts all the cities together in `Vec`s.
```rust
#[derive(Debug)]
@ -8213,7 +8213,7 @@ struct City {
}
#[derive(Debug)]
struct Cities {
struct CityData {
names: Vec<String>,
histories: Vec<Rc<String>>,
}