Skip to content

Commit 005ab57

Browse files
committed
ch04 所有権を理解するの和訳を最新版に更新
rust-lang/book@19c40bf
1 parent 49f93be commit 005ab57

File tree

51 files changed

+749
-1045
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+749
-1045
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "ownership"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
fn main() {
22
// ANCHOR: here
3-
{ // s is not valid here, it’s not yet declared
4-
let s = "hello"; // s is valid from this point forward
3+
{ // sは、ここでは有効ではない。まだ宣言されていない
4+
let s = "hello"; // sは、ここから有効になる
55

6-
// do stuff with s
7-
} // this scope is now over, and s is no longer valid
6+
// sで作業をする
7+
} // このスコープは終わり。もうsは有効ではない
88
// ANCHOR_END: here
99
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "ownership"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "ownership"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
fn main() {
2-
let s = String::from("hello"); // s comes into scope
2+
let s = String::from("hello"); // sがスコープに入る
33

4-
takes_ownership(s); // s's value moves into the function...
5-
// ... and so is no longer valid here
4+
takes_ownership(s); // sの値が関数にムーブされ...
5+
// ... ここではもう有効ではない
66

7-
let x = 5; // x comes into scope
7+
let x = 5; // xがスコープに入る
88

9-
makes_copy(x); // x would move into the function,
10-
// but i32 is Copy, so it’s okay to still
11-
// use x afterward
9+
makes_copy(x); // xも関数にムーブされるが、
10+
// i32はCopyなので、この後にxを使っても
11+
// 大丈夫
1212

13-
} // Here, x goes out of scope, then s. But because s's value was moved, nothing
14-
// special happens.
13+
} // ここでxがスコープを抜け、sもスコープを抜ける。ただし、sの値はムーブされているので、
14+
// 何も特別なことは起こらない。
1515

16-
fn takes_ownership(some_string: String) { // some_string comes into scope
16+
fn takes_ownership(some_string: String) { // some_stringがスコープに入る。
1717
println!("{}", some_string);
18-
} // Here, some_string goes out of scope and `drop` is called. The backing
19-
// memory is freed.
18+
} // ここでsome_stringがスコープを抜け、`drop`が呼ばれる。後ろ盾してたメモリが解放される。
19+
// 後ろ盾してたメモリが解放される。
2020

21-
fn makes_copy(some_integer: i32) { // some_integer comes into scope
21+
fn makes_copy(some_integer: i32) { // some_integerがスコープに入る
2222
println!("{}", some_integer);
23-
} // Here, some_integer goes out of scope. Nothing special happens.
23+
} // ここでsome_integerがスコープを抜ける。何も特別なことはない。
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "ownership"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
fn main() {
2-
let s1 = gives_ownership(); // gives_ownership moves its return
3-
// value into s1
2+
let s1 = gives_ownership(); // gives_ownershipは、戻り値をs1に
3+
// ムーブする
44

5-
let s2 = String::from("hello"); // s2 comes into scope
5+
let s2 = String::from("hello"); // s2がスコープに入る
66

7-
let s3 = takes_and_gives_back(s2); // s2 is moved into
8-
// takes_and_gives_back, which also
9-
// moves its return value into s3
10-
} // Here, s3 goes out of scope and is dropped. s2 goes out of scope but was
11-
// moved, so nothing happens. s1 goes out of scope and is dropped.
7+
let s3 = takes_and_gives_back(s2); // s2はtakes_and_gives_backにムーブされ
8+
// 戻り値もs3にムーブされる
9+
} // ここで、s3はスコープを抜け、ドロップされる。s2もスコープを抜けるが、ムーブされているので、
10+
// 何も起きない。s1もスコープを抜け、ドロップされる。
1211

13-
fn gives_ownership() -> String { // gives_ownership will move its
14-
// return value into the function
15-
// that calls it
12+
fn gives_ownership() -> String { // gives_ownershipは、戻り値を
13+
// 呼び出した関数にムーブする
1614

17-
let some_string = String::from("hello"); // some_string comes into scope
15+
let some_string = String::from("hello"); // some_stringがスコープに入る
1816

19-
some_string // some_string is returned and
20-
// moves out to the calling
21-
// function
17+
some_string // some_stringが返され、呼び出し元関数に
18+
// ムーブされる
2219
}
2320

24-
// takes_and_gives_back will take a String and return one
25-
fn takes_and_gives_back(a_string: String) -> String { // a_string comes into
26-
// scope
21+
// takes_and_gives_backは、Stringを一つ受け取り、返す。
22+
fn takes_and_gives_back(a_string: String) -> String { // a_stringがスコープに入る。
2723

28-
a_string // a_string is returned and moves out to the calling function
24+
a_string // a_stringが返され、呼び出し元関数にムーブされる
2925
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "ownership"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch04-understanding-ownership/listing-04-05/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ fn main() {
33

44
let (s2, len) = calculate_length(s1);
55

6+
//'{}'の長さは、{}です
67
println!("The length of '{}' is {}.", s2, len);
78
}
89

910
fn calculate_length(s: String) -> (String, usize) {
10-
let length = s.len(); // len() returns the length of a String
11+
let length = s.len(); // len()メソッドは、Stringの長さを返します
1112

1213
(s, length)
1314
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "ownership"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

0 commit comments

Comments
 (0)