Skip to content

ch04 所有権を理解するの和訳を最新版に更新 #252

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

Open
wants to merge 9 commits into
base: master-ja
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
ch03 一般的なプログラミングの概念の和訳を最新版に更新
  • Loading branch information
shinmili committed Feb 4, 2025
commit cf8947f79577c48a1cdfb6f67a15d28321cd5eeb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ fn main() {
let condition = true;
let number = if condition { 5 } else { 6 };

// numberの値は、{}です
println!("The value of number is: {}", number);
// numberの値は、{number}です
println!("The value of number is: {number}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fn main() {
let mut number = 3;

while number != 0 {
println!("{}!", number);
println!("{number}!");

number -= 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ fn main() {
let a = [10, 20, 30, 40, 50];

for element in a {
println!("the value is: {}", element);
println!("the value is: {element}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ error[E0384]: cannot assign twice to immutable variable `x`
| first assignment to `x`
| (`x`への最初の代入)
| help: consider making this binding mutable: `mut x`
3 | println!("The value of x is: {}", x);
3 | println!("The value of x is: {x}");
4 | x = 6;
| ^^^^^ cannot assign twice to immutable variable

For more information about this error, try `rustc --explain E0384`.
error: could not compile `variables` due to previous error
error: could not compile `variables` (bin "variables") due to 1 previous error
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
let x = 5;
println!("The value of x is: {}", x); // xの値は{}です
println!("The value of x is: {x}"); // xの値は{x}です
x = 6;
println!("The value of x is: {}", x);
println!("The value of x is: {x}");
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
let mut x = 5;
println!("The value of x is: {}", x);
println!("The value of x is: {x}");
x = 6;
println!("The value of x is: {}", x);
println!("The value of x is: {x}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ fn main() {

{
let x = x * 2;
println!("The value of x in the inner scope is: {}", x);
println!("The value of x in the inner scope is: {x}");
}

println!("The value of x is: {}", x);
println!("The value of x is: {x}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ error[E0308]: mismatched types (型が合いません)
3 | spaces = spaces.len();
| ^^^^^^^^^^^^ expected `&str`, found `usize`
| (&str型を予期しましたが、usizeが見つかりました)
|
help: try removing the method call
|
3 - spaces = spaces.len();
3 + spaces = spaces;
|

For more information about this error, try `rustc --explain E0308`.
error: could not compile `variables` due to previous error
error: could not compile `variables` (bin "variables") due to 1 previous error
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ fn main() {
// division
// 割り算
let quotient = 56.7 / 32.2;
let floored = 2 / 3; // Results in 0
// 結果は0
let truncated = -5 / 3; // Results in -1
// 結果は-1

// remainder
// 余り
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fn main() {
let c = 'z';
let z = 'ℤ';
let z: char = 'ℤ'; // with explicit type annotation
// 明示的型注釈付きで
let heart_eyed_cat = '😻'; //ハート目の猫
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ fn main() {

let (x, y, z) = tup;

println!("The value of y is: {}", y);
println!("The value of y is: {y}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ fn main() {

let element = a[index];

println!(
"The value of the element at index {} is: {}",
// {}番目の要素の値は{}です
index, element
);
println!("The value of the element at index {index} is: {element}");
// {index}番目の要素の値は{element}です
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ fn main() {
}

fn another_function(x: i32) {
println!("The value of x is: {}", x); // xの値は{}です
println!("The value of x is: {x}"); // xの値は{x}です
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ fn main() {
}

fn print_labeled_measurement(value: i32, unit_label: char) {
println!("The measurement is: {}{}", value, unit_label);
println!("The measurement is: {value}{unit_label}");
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
$ cargo run
Compiling functions v0.1.0 (file:///projects/functions)
error: expected expression, found statement (`let`)
(エラー: 式を予期しましたが、文が見つかりました (`let`))
error: expected expression, found `let` statement
(エラー: 式を予期しましたが、`let`文が見つかりました)
--> src/main.rs:2:14
|
2 | let x = (let y = 6);
| ^^^^^^^^^
| ^^^
|
= note: variable declaration using `let` is a statement
(注釈: `let`を使う変数宣言は、文です)

error[E0658]: `let` expressions in this position are experimental
--> src/main.rs:2:14
|
2 | let x = (let y = 6);
| ^^^^^^^^^
|
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
= note: only supported directly in conditions of `if` and `while` expressions
(注釈: `if` および `while` 式の条件部直下でのみ対応しています

warning: unnecessary parentheses around assigned value
--> src/main.rs:2:13
Expand All @@ -30,8 +21,7 @@ help: remove these parentheses
|
2 - let x = (let y = 6);
2 + let x = let y = 6;
|
|

For more information about this error, try `rustc --explain E0658`.
warning: `functions` (bin "functions") generated 1 warning
error: could not compile `functions` due to 2 previous errors; 1 warning emitted
error: could not compile `functions` (bin "functions") due to 1 previous error; 1 warning emitted
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ fn main() {
x + 1
};

println!("The value of y is: {}", y);
println!("The value of y is: {y}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ fn five() -> i32 {
fn main() {
let x = five();

println!("The value of x is: {}", x);
println!("The value of x is: {x}");
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn main() {
let x = plus_one(5);

println!("The value of x is: {}", x);
println!("The value of x is: {x}");
}

fn plus_one(x: i32) -> i32 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ error[E0308]: mismatched types
| |
| implicitly returns `()` as its body has no tail or `return` expression
8 | x + 1;
| - help: consider removing this semicolon
| - help: remove this semicolon to return this value

For more information about this error, try `rustc --explain E0308`.
error: could not compile `functions` due to previous error
error: could not compile `functions` (bin "functions") due to 1 previous error
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn main() {
let x = plus_one(5);

println!("The value of x is: {}", x);
println!("The value of x is: {x}");
}

fn plus_one(x: i32) -> i32 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ error[E0308]: mismatched types
| (bool型を予期したのに、整数変数が見つかりました)

For more information about this error, try `rustc --explain E0308`.
error: could not compile `branches` due to previous error
error: could not compile `branches` (bin "branches") due to 1 previous error
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ error[E0308]: `if` and `else` have incompatible types
| expected because of this

For more information about this error, try `rustc --explain E0308`.
error: could not compile `branches` due to previous error
error: could not compile `branches` (bin "branches") due to 1 previous error
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ fn main() {

let number = if condition { 5 } else { "six" };

println!("The value of number is: {}", number);
println!("The value of number is: {number}");
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
fn main() {
let mut count = 0;
'counting_up: loop {
println!("count = {}", count);
println!("count = {count}");
let mut remaining = 10;

loop {
println!("remaining = {}", remaining);
println!("remaining = {remaining}");
if remaining == 9 {
break;
}
Expand All @@ -17,5 +17,5 @@ fn main() {

count += 1;
}
println!("End count = {}", count);
println!("End count = {count}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ fn main() {
}
};

println!("The result is {}", result);
println!("The result is {result}");
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
for number in (1..4).rev() {
println!("{}!", number);
println!("{number}!");
}
println!("LIFTOFF!!!");
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
$ cargo build
Compiling no_type_annotations v0.1.0 (file:///projects/no_type_annotations)
error[E0282]: type annotations needed
error[E0284]: type annotations needed
(型注釈が必要です)
--> src/main.rs:2:9
|
2 | let guess = "42".parse().expect("Not a number!");
| ^^^^^ consider giving `guess` a type
| (`guess`に型を与えることを検討してください)
| ^^^^^ ----- type must be known at this point
| (型はこの時点で既知でなくてはなりません)
|
= note: cannot satisfy `<_ as FromStr>::Err == _`
(`<_ as FromStr>::Err == _`を満たすことができません)
help: consider giving `guess` an explicit type
| (`guess`に型を与えることを検討してください)
|
2 | let guess: /* Type */ = "42".parse().expect("Not a number!");
| ++++++++++++

For more information about this error, try `rustc --explain E0282`.
error: could not compile `no_type_annotations` due to previous error
For more information about this error, try `rustc --explain E0284`.
error: could not compile `no_type_annotations` (bin "no_type_annotations") due to 1 previous error
14 changes: 8 additions & 6 deletions src/ch03-00-common-programming-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@ them early will give you a strong core to start from.
これらの基礎は全てのRustプログラムに存在するものであり、それらを早期に学ぶことにより、強力な基礎を築くことになるでしょう。

<!--
> ### Keywords
> #### Keywords
>
> The Rust language has a set of *keywords* that have been reserved for use by
> the language only, much as in other languages. Keep in mind that you cannot
> use these words as names of variables or functions. Most of the keywords have
> The Rust language has a set of *keywords* that are reserved for use by the
> language only, much as in other languages. Keep in mind that you cannot use
> these words as names of variables or functions. Most of the keywords have
> special meanings, and you’ll be using them to do various tasks in your Rust
> programs; a few have no current functionality associated with them but have
> been reserved for functionality that might be added to Rust in the future. You
> can find a list of the keywords in Appendix A.
> can find a list of the keywords in [Appendix A][appendix_a].
-->

> ### キーワード
> #### キーワード
>
> Rust言語にも他の言語同様、キーワードが存在し、これらは言語だけが使用できるようになっています。
> これらの単語は、変数や関数名には使えないことを弁えておいてください。ほとんどのキーワードは、特別な意味を持っており、
> 自らのRustプログラムにおいて、様々な作業をこなすために使用することができます;
> いくつかは、紐付けられた機能がないものの、将来Rustに追加されるかもしれない機能用に予約されています。
> キーワードの一覧は、付録Aで確認できます。

[appendix_a]: appendix-01-keywords.md
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy