Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 08-01 #94

Merged
merged 4 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions listings/ch08-common-collections/listing-08-04/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fn main() {
{
let v = vec![1, 2, 3, 4];

// do stuff with v
} // <- v goes out of scope and is freed here
// vで作業をする
} // <- vはここでスコープを抜け、解放される
// ANCHOR_END: here
}
2 changes: 2 additions & 0 deletions listings/ch08-common-collections/listing-08-05/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ fn main() {
println!("The third element is {}", third);

match v.get(2) {
// "3つ目の要素は{}です"
Some(third) => println!("The third element is {}", third),
// "3つ目の要素はありません。"
None => println!("There is no third element."),
}
// ANCHOR_END: here
Expand Down
4 changes: 4 additions & 0 deletions listings/ch08-common-collections/listing-08-07/output.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
$ cargo run
Compiling collections v0.1.0 (file:///projects/collections)
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable
(エラー: 不変としても借用されているので、`v`を可変で借用できません)
--> src/main.rs:6:5
|
4 | let first = &v[0];
| - immutable borrow occurs here
| (不変借用はここで発生しています)
5 |
6 | v.push(6);
| ^^^^^^^^^ mutable borrow occurs here
| (可変借用はここで発生しています)
7 |
8 | println!("The first element is: {}", first);
| ----- immutable borrow later used here
| (その後、不変借用はここで使われています)

error: aborting due to previous error

Expand Down
Loading