update: 不知道用的是不是mdbook,先按mdbook的格式把代码改的符合逻辑

pull/156/head
chenxuuu 3 years ago
parent 23bb6e2a9c
commit fa7b67e1c1
No known key found for this signature in database
GPG Key ID: B1A462D4300513F3

@ -110,24 +110,30 @@ fn build_user(email: String, username: String) -> User {
> 值的注意的是:`username`所有权被转移给了`user2`,导致了`user1`无法再被使用,但是并不代表`user1`内部的其它字段不能被继续使用,例如: > 值的注意的是:`username`所有权被转移给了`user2`,导致了`user1`无法再被使用,但是并不代表`user1`内部的其它字段不能被继续使用,例如:
```rust ```rust
let user1 = User { # #[derive(Debug)]
email: String::from("someone@example.com"), # struct User {
username: String::from("someusername123"), # active: bool,
active: true, # username: String,
sign_in_count: 1, # email: String,
}; # sign_in_count: u64,
# }
let user2 = User { # fn main() {
active: user1.active, let user1 = User {
username: user1.username, email: String::from("someone@example.com"),
email: String::from("another@example.com"), username: String::from("someusername123"),
sign_in_count: user1.sign_in_count, active: true,
}; sign_in_count: 1,
};
println!("{}", user1.active); let user2 = User {
active: user1.active,
// 下面这行会报错 username: user1.username,
//println!("{}", user1.username); email: String::from("another@example.com"),
sign_in_count: user1.sign_in_count,
};
println!("{}", user1.active);
// 下面这行会报错
println!("{:?}", user1);
# }
``` ```
## 结构体的内存排列 ## 结构体的内存排列

Loading…
Cancel
Save