Skip to content

第1~20章と付録以外の部分の和訳を最新版に更新 #275

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 58 commits into
base: master-ja
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e685c96
ch02 数当てゲームのプログラミングの和訳を最新版に更新
shinmili May 26, 2024
db3a649
リンク漏れ修正
shinmili Nov 28, 2024
24f5af0
コメントの位置修正
shinmili Dec 26, 2024
cf8947f
ch03 一般的なプログラミングの概念の和訳を最新版に更新
shinmili May 26, 2024
42a63a5
リンク漏れ修正
shinmili Nov 28, 2024
e0d2a48
誤字修正
shinmili Jan 31, 2025
42cf09e
ch04 所有権を理解するの和訳を最新版に更新
shinmili May 26, 2024
138f7fc
コメント閉じ忘れ修正
shinmili Nov 28, 2024
f5f69e9
コードブロックの訳し漏れ修正
shinmili Nov 28, 2024
40d8fd5
ch05 構造体を使用して関係のあるデータを構造化するの和訳を最新版に更新
shinmili May 26, 2024
70c7a13
ch06 Enumとパターンマッチングの和訳を最新版に更新
shinmili May 26, 2024
2f70d34
ch07 肥大化していくプロジェクトをパッケージ、クレート、モジュールを利用して管理するの和訳を最新版に更新
shinmili May 26, 2024
0c0c9d5
消し忘れた段落を削除
shinmili Nov 29, 2024
9eb0aa4
読点の修正
shinmili Nov 29, 2024
1139c13
ch08 一般的なコレクションの和訳を最新版に更新
shinmili May 26, 2024
32a5e00
誤字修正
shinmili Nov 30, 2024
cbd1f9c
消し忘れた段落を削除
shinmili Nov 30, 2024
777e045
コメントの閉じ方の誤りを修正
shinmili Nov 30, 2024
6da5374
修正漏れを修正
shinmili Nov 30, 2024
75aeb75
doc.rust-lang.org 内でのみ機能する相対リンクを修正
shinmili Nov 30, 2024
93e7c99
ch09 エラー処理の和訳を最新版に更新
shinmili May 26, 2024
ee5f863
不要な記号の削除
shinmili Nov 30, 2024
1e6ccf0
消し忘れた段落を削除
shinmili Nov 30, 2024
4e664a9
コメントの位置修正
shinmili Dec 27, 2024
4e3d9ea
ch10 ジェネリック型、トレイト、ライフタイムの和訳を最新版に更新
shinmili May 26, 2024
439eeec
消し忘れた段落を削除
shinmili Nov 30, 2024
fb60cce
ch11 自動テストを書くの和訳を最新版に更新
shinmili May 26, 2024
91b9e1a
見出しレベル誤りを修正
shinmili Dec 1, 2024
059af4e
消し忘れた段落を削除
shinmili Dec 1, 2024
5464a6e
余計な空行を削除
shinmili Dec 27, 2024
06f787f
訳し漏れの翻訳を追加
shinmili Jan 31, 2025
fff91f0
誤字修正
shinmili Jan 31, 2025
57c5588
ch12 入出力プロジェクト: コマンドラインプログラムを構築するの和訳を最新版に更新
shinmili May 26, 2024
e042c99
ch13 関数型言語の機能: イテレータとクロージャの和訳を最新版に更新
shinmili May 26, 2024
4543380
見出しレベル誤りを修正
shinmili Dec 1, 2024
57b18f1
訳し忘れを修正
shinmili Dec 1, 2024
db47fd2
ch14 CargoとCrates.ioについてより詳しくの和訳を最新版に更新
shinmili May 26, 2024
e3bf9f9
ch15 スマートポインタの和訳を最新版に更新
shinmili May 26, 2024
e49e340
消し忘れた段落を削除
shinmili Dec 7, 2024
64432c2
ch16 恐れるな!並行性の和訳を最新版に更新
shinmili May 26, 2024
bd648eb
ch17 Rustのオブジェクト指向プログラミング機能の和訳を最新版に更新
shinmili May 26, 2024
7f4328c
ch18 パターンとマッチングの和訳を最新版に更新
shinmili May 26, 2024
46a06ad
ch19 高度な機能の和訳を最新版に更新
shinmili May 26, 2024
a8f53a5
markdown の誤りを修正
shinmili Dec 8, 2024
e657cc7
消し忘れた段落を削除
shinmili Dec 8, 2024
634ef1a
誤リンク修正
shinmili Jan 31, 2025
7351cd9
ch20 最後のプロジェクト: マルチスレッドのWebサーバを構築するの和訳を最新版に更新
shinmili May 26, 2024
d6477e2
付録A: キーワードの和訳をアップデート
shinmili May 26, 2024
07bc7e9
付録B: 演算子と記号の和訳をアップデート
shinmili May 26, 2024
8a44126
付録C: 導出可能なトレイトの和訳をアップデート
shinmili May 26, 2024
61796c9
付録D: 便利な開発ツールの和訳をアップデート
shinmili May 26, 2024
11c6f83
付録F: 本の翻訳の和訳をアップデート
shinmili May 26, 2024
6fb6df6
付録G: Rustの作られ方と“Nightly Rust”の和訳をアップデート
shinmili May 26, 2024
aceff44
訳し忘れを修正
shinmili Dec 8, 2024
ae12469
表内の行の削除・並び替えに合わせて修正
shinmili Dec 8, 2024
b5c6eaa
消し忘れた見出しを削除
shinmili Dec 8, 2024
5090ec4
コードブロックの ferris 関連の変更を同期 (4921fde2, d34ea05, 71d41266)
shinmili May 26, 2024
ec529e1
title-page.md を更新
shinmili May 26, 2024
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
ch13 関数型言語の機能: イテレータとクロージャの和訳を最新版に更新
  • Loading branch information
shinmili committed Feb 4, 2025
commit e042c9978d8c6536a0b9a850e376cd7b069c8cc8
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "minigrep"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,42 @@ use std::fs;

pub struct Config {
pub query: String,
pub filename: String,
pub case_sensitive: bool,
pub file_path: String,
pub ignore_case: bool,
}

// ANCHOR: ch13
impl Config {
pub fn new(args: &[String]) -> Result<Config, &'static str> {
pub fn build(args: &[String]) -> Result<Config, &'static str> {
if args.len() < 3 {
return Err("not enough arguments");
}

let query = args[1].clone();
let filename = args[2].clone();
let file_path = args[2].clone();

let case_sensitive = env::var("CASE_INSENSITIVE").is_err();
let ignore_case = env::var("IGNORE_CASE").is_ok();

Ok(Config {
query,
filename,
case_sensitive,
file_path,
ignore_case,
})
}
}
// ANCHOR_END: ch13

pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
let contents = fs::read_to_string(config.filename)?;
let contents = fs::read_to_string(config.file_path)?;

let results = if config.case_sensitive {
search(&config.query, &contents)
} else {
let results = if config.ignore_case {
search_case_insensitive(&config.query, &contents)
} else {
search(&config.query, &contents)
};

for line in results {
println!("{}", line);
println!("{line}");
}

Ok(())
Expand Down Expand Up @@ -104,5 +104,3 @@ Trust me.";
);
}
}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ use minigrep::Config;
fn main() {
let args: Vec<String> = env::args().collect();

let config = Config::new(&args).unwrap_or_else(|err| {
println!("Problem parsing arguments: {}", err);
let config = Config::build(&args).unwrap_or_else(|err| {
println!("Problem parsing arguments: {err}");
process::exit(1);
});

if let Err(e) = minigrep::run(config) {
println!("Application error: {}", e);

println!("Application error: {e}");
process::exit(1);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "minigrep"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,40 @@ use std::fs;

pub struct Config {
pub query: String,
pub filename: String,
pub case_sensitive: bool,
pub file_path: String,
pub ignore_case: bool,
}

impl Config {
pub fn new(args: &[String]) -> Result<Config, &'static str> {
pub fn build(args: &[String]) -> Result<Config, &'static str> {
if args.len() < 3 {
return Err("not enough arguments");
}

let query = args[1].clone();
let filename = args[2].clone();
let file_path = args[2].clone();

let case_sensitive = env::var("CASE_INSENSITIVE").is_err();
let ignore_case = env::var("IGNORE_CASE").is_ok();

Ok(Config {
query,
filename,
case_sensitive,
file_path,
ignore_case,
})
}
}

pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
let contents = fs::read_to_string(config.filename)?;
let contents = fs::read_to_string(config.file_path)?;

let results = if config.case_sensitive {
search(&config.query, &contents)
} else {
let results = if config.ignore_case {
search_case_insensitive(&config.query, &contents)
} else {
search(&config.query, &contents)
};

for line in results {
println!("{}", line);
println!("{line}");
}

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ use minigrep::Config;
fn main() {
let args: Vec<String> = env::args().collect();

let config = Config::new(&args).unwrap_or_else(|err| {
eprintln!("Problem parsing arguments: {}", err);
let config = Config::build(&args).unwrap_or_else(|err| {
eprintln!("Problem parsing arguments: {err}");
process::exit(1);
});

// --snip--
// ANCHOR_END: ch13

if let Err(e) = minigrep::run(config) {
eprintln!("Application error: {}", e);

eprintln!("Application error: {e}");
process::exit(1);
}
// ANCHOR: ch13
Expand Down
5 changes: 3 additions & 2 deletions listings/ch13-functional-features/listing-13-01/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions listings/ch13-functional-features/listing-13-01/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "workout-app"
name = "shirt-company"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
6 changes: 6 additions & 0 deletions listings/ch13-functional-features/listing-13-01/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$ cargo run
Compiling shirt-company v0.1.0 (file:///projects/shirt-company)
Finished dev [unoptimized + debuginfo] target(s) in 0.27s
Running `target/debug/shirt-company`
The user with preference Some(Red) gets Red
The user with preference None gets Blue
60 changes: 51 additions & 9 deletions listings/ch13-functional-features/listing-13-01/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,54 @@
// ANCHOR: here
use std::thread;
use std::time::Duration;
#[derive(Debug, PartialEq, Copy, Clone)]
enum ShirtColor {
Red,
Blue,
}

struct Inventory {
shirts: Vec<ShirtColor>,
}

impl Inventory {
fn giveaway(&self, user_preference: Option<ShirtColor>) -> ShirtColor {
user_preference.unwrap_or_else(|| self.most_stocked())
}

fn simulated_expensive_calculation(intensity: u32) -> u32 {
println!("calculating slowly...");
thread::sleep(Duration::from_secs(2));
intensity
fn most_stocked(&self) -> ShirtColor {
let mut num_red = 0;
let mut num_blue = 0;

for color in &self.shirts {
match color {
ShirtColor::Red => num_red += 1,
ShirtColor::Blue => num_blue += 1,
}
}
if num_red > num_blue {
ShirtColor::Red
} else {
ShirtColor::Blue
}
}
}
// ANCHOR_END: here

fn main() {}
fn main() {
let store = Inventory {
shirts: vec![ShirtColor::Blue, ShirtColor::Red, ShirtColor::Blue],
};

let user_pref1 = Some(ShirtColor::Red);
let giveaway1 = store.giveaway(user_pref1);
println!(
// "好み{:?}を持つユーザは{:?}を得ます"
"The user with preference {:?} gets {:?}",
user_pref1, giveaway1
);

let user_pref2 = None;
let giveaway2 = store.giveaway(user_pref2);
println!(
// "好み{:?}を持つユーザは{:?}を得ます"
"The user with preference {:?} gets {:?}",
user_pref2, giveaway2
);
}
3 changes: 1 addition & 2 deletions listings/ch13-functional-features/listing-13-02/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "workout-app"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
30 changes: 22 additions & 8 deletions listings/ch13-functional-features/listing-13-02/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
use std::thread;
use std::time::Duration;

fn simulated_expensive_calculation(intensity: u32) -> u32 {
println!("calculating slowly...");
thread::sleep(Duration::from_secs(2));
intensity
}
fn generate_workout(intensity: u32, random_number: u32) {
// ANCHOR: here
let expensive_closure = |num: u32| -> u32 {
println!("calculating slowly...");
thread::sleep(Duration::from_secs(2));
num
};
// ANCHOR_END: here

fn generate_workout(intensity: u32, random_number: u32) {}
if intensity < 25 {
println!("Today, do {} pushups!", expensive_closure(intensity));
println!("Next, do {} situps!", expensive_closure(intensity));
} else {
if random_number == 3 {
println!("Take a break today! Remember to stay hydrated!");
} else {
println!(
"Today, run for {} minutes!",
expensive_closure(intensity)
);
}
}
}

// ANCHOR: here
fn main() {
let simulated_user_specified_value = 10;
let simulated_random_number = 7;

generate_workout(simulated_user_specified_value, simulated_random_number);
}
// ANCHOR_END: here
2 changes: 1 addition & 1 deletion listings/ch13-functional-features/listing-13-03/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions listings/ch13-functional-features/listing-13-03/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "workout-app"
name = "closure-example"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
33 changes: 33 additions & 0 deletions listings/ch13-functional-features/listing-13-03/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
$ cargo run
Compiling closure-example v0.1.0 (file:///projects/closure-example)
error[E0308]: mismatched types
(エラー: 型が合いません)
--> src/main.rs:5:29
|
5 | let n = example_closure(5);
| --------------- ^- help: try using a conversion method: `.to_string()`
| | | (ヘルプ: 変換メソッド`.to_string()`を使用してみてください)
| | |
| | expected `String`, found integer
| | (`String`を予期していましたが、整数が見つかりました)
| arguments to this function are incorrect
| (この関数への引数が正しくありません)
|
note: expected because the closure was earlier called with an argument of type `String`
(注釈: クロージャは以前に型`String`を持つ引数とともに呼ばれているため、これが予期されています)
--> src/main.rs:4:29
|
4 | let s = example_closure(String::from("hello"));
| --------------- ^^^^^^^^^^^^^^^^^^^^^ expected because this argument is of type `String`
| | (この引数が型`String`を持つことから予期されています)
| |
| in this closure call
| (このクロージャ呼び出しで)
note: closure parameter defined here
--> src/main.rs:2:28
|
2 | let example_closure = |x| x;
| ^

For more information about this error, try `rustc --explain E0308`.
error: could not compile `closure-example` (bin "closure-example") due to 1 previous error
Loading