Skip to content

Commit 262987a

Browse files
committed
ch19 高度な機能の和訳を最新版に更新
rust-lang/book@19c40bf
1 parent 3c459bb commit 262987a

File tree

86 files changed

+957
-1265
lines changed

Some content is hidden

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

86 files changed

+957
-1265
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "unsafe-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "unsafe-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "unsafe-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "unsafe-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "unsafe-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
$ cargo run
22
Compiling unsafe-example v0.1.0 (file:///projects/unsafe-example)
3-
error[E0499]: cannot borrow `*slice` as mutable more than once at a time
4-
--> src/main.rs:6:30
3+
error[E0499]: cannot borrow `*values` as mutable more than once at a time
4+
(エラー: 一度に2回以上、`*values`を可変で借用できません)
5+
--> src/main.rs:6:31
56
|
6-
1 | fn split_at_mut(slice: &mut [i32], mid: usize) -> (&mut [i32], &mut [i32]) {
7-
| - let's call the lifetime of this reference `'1`
7+
1 | fn split_at_mut(values: &mut [i32], mid: usize) -> (&mut [i32], &mut [i32]) {
8+
| - let's call the lifetime of this reference `'1`
9+
| (この参照のライフタイムを`'1`とします)
810
...
9-
6 | (&mut slice[..mid], &mut slice[mid..])
10-
| -------------------------^^^^^--------
11-
| | | |
12-
| | | second mutable borrow occurs here
11+
6 | (&mut values[..mid], &mut values[mid..])
12+
| --------------------------^^^^^^--------
13+
| | | |
14+
| | | second mutable borrow occurs here
15+
| | | (2回目の可変参照はここで発生します)
1316
| | first mutable borrow occurs here
14-
| returning this value requires that `*slice` is borrowed for `'1`
15-
16-
error: aborting due to previous error
17+
| | (1回目の可変参照はここで発生します)
18+
| returning this value requires that `*values` is borrowed for `'1`
19+
| (この値を返すためには`*values`が`'1`の間借用されていることが必要です)
1720

1821
For more information about this error, try `rustc --explain E0499`.
19-
error: could not compile `unsafe-example`.
20-
21-
To learn more, run the command again with --verbose.
22+
error: could not compile `unsafe-example` (bin "unsafe-example") due to 1 previous error

listings/ch19-advanced-features/listing-19-05/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// ANCHOR: here
2-
fn split_at_mut(slice: &mut [i32], mid: usize) -> (&mut [i32], &mut [i32]) {
3-
let len = slice.len();
2+
fn split_at_mut(values: &mut [i32], mid: usize) -> (&mut [i32], &mut [i32]) {
3+
let len = values.len();
44

55
assert!(mid <= len);
66

7-
(&mut slice[..mid], &mut slice[mid..])
7+
(&mut values[..mid], &mut values[mid..])
88
}
99
// ANCHOR_END: here
1010

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "unsafe-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch19-advanced-features/listing-19-06/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ANCHOR: here
22
use std::slice;
33

4-
fn split_at_mut(slice: &mut [i32], mid: usize) -> (&mut [i32], &mut [i32]) {
5-
let len = slice.len();
6-
let ptr = slice.as_mut_ptr();
4+
fn split_at_mut(values: &mut [i32], mid: usize) -> (&mut [i32], &mut [i32]) {
5+
let len = values.len();
6+
let ptr = values.as_mut_ptr();
77

88
assert!(mid <= len);
99

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "unsafe-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch19-advanced-features/listing-19-07/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ fn main() {
55
let address = 0x01234usize;
66
let r = address as *mut i32;
77

8-
let slice: &[i32] = unsafe { slice::from_raw_parts_mut(r, 10000) };
8+
let values: &[i32] = unsafe { slice::from_raw_parts_mut(r, 10000) };
99
// ANCHOR_END: here
1010
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "unsafe-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch19-advanced-features/listing-19-08/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extern "C" {
44

55
fn main() {
66
unsafe {
7+
// -3の絶対値は、Cによると{}
78
println!("Absolute value of -3 according to C: {}", abs(-3));
89
}
910
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "unsafe-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "unsafe-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "unsafe-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
unsafe trait Foo {
22
// methods go here
3+
// メソッドがここに来る
34
}
45

56
unsafe impl Foo for i32 {
67
// method implementations go here
8+
// メソッドの実装がここに来る
79
}
810

911
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "traits-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "traits-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "traits-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch19-advanced-features/listing-19-14/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::ops::Add;
22

3-
#[derive(Debug, PartialEq)]
3+
#[derive(Debug, Copy, Clone, PartialEq)]
44
struct Point {
55
x: i32,
66
y: i32,
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "traits-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "traits-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch19-advanced-features/listing-19-16/src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@ struct Human;
1111

1212
impl Pilot for Human {
1313
fn fly(&self) {
14+
// こちら機長です。
1415
println!("This is your captain speaking.");
1516
}
1617
}
1718

1819
impl Wizard for Human {
1920
fn fly(&self) {
21+
// 上がれ!
2022
println!("Up!");
2123
}
2224
}
2325

2426
impl Human {
2527
fn fly(&self) {
28+
// *激しく腕を振る*
2629
println!("*waving arms furiously*");
2730
}
2831
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "traits-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "traits-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "traits-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch19-advanced-features/listing-19-19/src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ struct Dog;
66

77
impl Dog {
88
fn baby_name() -> String {
9+
// スポット
910
String::from("Spot")
1011
}
1112
}
1213

1314
impl Animal for Dog {
1415
fn baby_name() -> String {
16+
// 子犬
1517
String::from("puppy")
1618
}
1719
}
1820

1921
fn main() {
22+
// 赤ちゃん犬は{}と呼ばれる
2023
println!("A baby dog is called a {}", Dog::baby_name());
2124
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "traits-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
$ cargo run
22
Compiling traits-example v0.1.0 (file:///projects/traits-example)
3-
error[E0283]: type annotations needed
3+
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
4+
(エラー: 対応する`impl`型を指定せずにトレイト上の関連関数を呼び出すことはできません)
45
--> src/main.rs:20:43
56
|
67
2 | fn baby_name() -> String;
7-
| ------------------------- required by `Animal::baby_name`
8+
| ------------------------- `Animal::baby_name` defined here
9+
| (`Animal::baby_name`はここで定義されています)
810
...
911
20 | println!("A baby dog is called a {}", Animal::baby_name());
10-
| ^^^^^^^^^^^^^^^^^ cannot infer type
12+
| ^^^^^^^^^^^^^^^^^ cannot call associated function of trait
13+
| (トレイトの関連関数を呼び出すことができません)
1114
|
12-
= note: cannot resolve `_: Animal`
13-
14-
error: aborting due to previous error
15-
16-
For more information about this error, try `rustc --explain E0283`.
17-
error: could not compile `traits-example`.
15+
help: use the fully-qualified path to the only available implementation
16+
(ヘルプ: 利用可能な実装のうち1つを指すフルパスを使用してください)
17+
|
18+
20 | println!("A baby dog is called a {}", <Dog as Animal>::baby_name());
19+
| +++++++ +
1820

19-
To learn more, run the command again with --verbose.
21+
For more information about this error, try `rustc --explain E0790`.
22+
error: could not compile `traits-example` (bin "traits-example") due to 1 previous error
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "traits-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "traits-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "traits-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "types-example"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "types-example"
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)