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`内部的其它字段不能被继续使用,例如:
```rust
# #[derive(Debug)]
# struct User {
# active: bool,
# username: String,
# email: String,
# sign_in_count: u64,
# }
# fn main() {
let user1 = User {
email: String::from("someone@example.com"),
username: String::from("someusername123"),
active: true,
sign_in_count: 1,
};
let user2 = User {
active: user1.active,
username: user1.username,
email: String::from("another@example.com"),
sign_in_count: user1.sign_in_count,
};
println!("{}", user1.active);
// 下面这行会报错
//println!("{}", user1.username);
println!("{:?}", user1);
# }
```
## 结构体的内存排列

Loading…
Cancel
Save