Skip to content

Commit 683dd54

Browse files
committed
ci: generate pages at 39ab0de [ci skip]
1 parent 39ab0de commit 683dd54

7 files changed

+548
-320
lines changed

docs/ch03-01-variables-and-mutability.html

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ <h2 id="変数と可変性"><a class="header" href="#変数と可変性">変数
179179
<span class="filename">Filename: src/main.rs</span>
180180
-->
181181
<p><span class="filename">ファイル名: src/main.rs</span></p>
182-
<pre><code class="language-rust ignore">fn main() {
182+
<pre><code class="language-rust ignore does_not_compile">fn main() {
183183
let x = 5;
184-
println!(&quot;The value of x is: {}&quot;, x); // xの値は{}です
184+
println!(&quot;The value of x is: {}&quot;, x);; // xの値は{}です
185185
x = 6;
186186
println!(&quot;The value of x is: {}&quot;, x);
187187
}
@@ -191,16 +191,24 @@ <h2 id="変数と可変性"><a class="header" href="#変数と可変性">変数
191191
message, as shown in this output:
192192
-->
193193
<p>これを保存し、<code>cargo run</code>コマンドでプログラムを走らせてください。次の出力に示されているようなエラーメッセージを受け取るはずです:</p>
194-
<pre><code class="language-text">error[E0384]: cannot assgin twice immutable variable `x`
194+
<pre><code class="language-console">$ cargo run
195+
Compiling variables v0.1.0 (file:///projects/variables)
196+
error[E0384]: cannot assign twice to immutable variable `x`
195197
(不変変数`x`に2回代入できません)
196198
--&gt; src/main.rs:4:5
197199
|
198200
2 | let x = 5;
199-
| - first assignment to `x`
201+
| -
202+
| |
203+
| first assignment to `x`
200204
| (`x`への最初の代入)
205+
| help: consider making this binding mutable: `mut x`
201206
3 | println!(&quot;The value of x is: {}&quot;, x);
202207
4 | x = 6;
203208
| ^^^^^ cannot assign twice to immutable variable
209+
210+
For more information about this error, try `rustc --explain E0384`.
211+
error: could not compile `variables` due to previous error
204212
</code></pre>
205213
<!--
206214
This example shows how the compiler helps you find errors in your programs.
@@ -270,9 +278,9 @@ <h2 id="変数と可変性"><a class="header" href="#変数と可変性">変数
270278
When we run the program now, we get this:
271279
-->
272280
<p>今、このプログラムを走らせると、以下のような出力が得られます:</p>
273-
<pre><code class="language-text">$ cargo run
281+
<pre><code class="language-console">$ cargo run
274282
Compiling variables v0.1.0 (file:///projects/variables)
275-
Finished dev [unoptimized + debuginfo] target(s) in 0.30 secs
283+
Finished dev [unoptimized + debuginfo] target(s) in 0.30s
276284
Running `target/debug/variables`
277285
The value of x is: 5 (xの値は5です)
278286
The value of x is: 6
@@ -394,27 +402,33 @@ <h3 id="シャドーイング"><a class="header" href="#シャドーイング">
394402

395403
let x = x + 1;
396404

397-
let x = x * 2;
405+
{
406+
let x = x * 2;
407+
println!(&quot;The value of x in the inner scope is: {}&quot;, x);
408+
}
398409

399410
println!(&quot;The value of x is: {}&quot;, x);
400411
}
401412
</code></pre></pre>
402413
<!--
403414
This program first binds `x` to a value of `5`. Then it shadows `x` by
404415
repeating `let x =`, taking the original value and adding `1` so the value of
405-
`x` is then `6`. The third `let` statement also shadows `x`, multiplying the
406-
previous value by `2` to give `x` a final value of `12`. Wehn we run this
407-
program, it will output the following:
416+
`x` is then `6`. Then, within an inner scope, the third `let` statement also
417+
shadows `x`, multiplying the previous value by `2` to give `x` a value of `12`.
418+
When that scope is over, the inner shadowing ends and `x` returns to being `6`.
419+
When we run this program, it will output the following:
408420
-->
409421
<p>このプログラムはまず、<code>x</code><code>5</code>という値に束縛します。それから<code>let x =</code>を繰り返すことで<code>x</code>を覆い隠し、
410422
元の値に<code>1</code>を加えることになるので、<code>x</code>の値は<code>6</code>になります。
411423
3番目の<code>let</code>文も<code>x</code>を覆い隠し、以前の値に<code>2</code>をかけることになるので、<code>x</code>の最終的な値は<code>12</code>になります。
424+
括弧を抜けるとシャドーイングは終了し、<code>x</code>の値は元の<code>6</code>に戻ります。
412425
このプログラムを走らせたら、以下のように出力するでしょう:</p>
413-
<pre><code class="language-text">$ cargo run
426+
<pre><code class="language-console">$ cargo run
414427
Compiling variables v0.1.0 (file:///projects/variables)
415-
Finished dev [unoptimized + debuginfo] target(s) in 0.31 secs
428+
Finished dev [unoptimized + debuginfo] target(s) in 0.31s
416429
Running `target/debug/variables`
417-
The value of x is: 12
430+
The value of x in the inner scope is: 12
431+
The value of x is: 6
418432
</code></pre>
419433
<!--
420434
Shadowing is different than marking a variable as `mut`, because we’ll get a
@@ -437,11 +451,9 @@ <h3 id="シャドーイング"><a class="header" href="#シャドーイング">
437451
値の型を変えつつ、同じ変数名を使いまわせることです。例えば、
438452
プログラムがユーザに何らかのテキストに対して空白文字を入力することで何個分のスペースを表示したいかを尋ねますが、
439453
ただ、実際にはこの入力を数値として保持したいとしましょう:</p>
440-
<pre><pre class="playground"><code class="language-rust">
441-
<span class="boring">#![allow(unused)]
442-
</span><span class="boring">fn main() {
443-
</span>let spaces = &quot; &quot;;
444-
let spaces = spaces.len();
454+
<pre><pre class="playground"><code class="language-rust"><span class="boring">fn main() {
455+
</span> let spaces = &quot; &quot;;
456+
let spaces = spaces.len();
445457
<span class="boring">}
446458
</span></code></pre></pre>
447459
<!--
@@ -457,23 +469,29 @@ <h3 id="シャドーイング"><a class="header" href="#シャドーイング">
457469
異なる名前を思いつく必要がなくなるわけです。<code>spaces_str</code><code>spaces_num</code>などですね; 代わりに、
458470
よりシンプルな<code>spaces</code>という名前を再利用できるわけです。一方で、この場合に<code>mut</code>を使おうとすると、
459471
以下に示した通りですが、コンパイルエラーになるわけです:</p>
460-
<pre><code class="language-rust ignore">let mut spaces = &quot; &quot;;
461-
spaces = spaces.len();
462-
</code></pre>
472+
<pre><code class="language-rust ignore does_not_compile"><span class="boring">fn main() {
473+
</span> let mut spaces = &quot; &quot;;
474+
spaces = spaces.len();
475+
<span class="boring">}
476+
</span></code></pre>
463477
<!--
464478
The error says we’re not allowed to mutate a variable’s
465479
type:
466480
-->
467481
<p>変数の型を可変にすることは許されていないと言われているわけです:</p>
468-
<pre><code class="language-text">error[E0308]: mismatched types (型が合いません)
482+
<pre><code class="language-console">$ cargo run
483+
Compiling variables v0.1.0 (file:///projects/variables)
484+
error[E0308]: mismatched types (型が合いません)
469485
--&gt; src/main.rs:3:14
470486
|
487+
2 | let mut spaces = &quot; &quot;;
488+
| ----- expected due to this value
471489
3 | spaces = spaces.len();
472-
| ^^^^^^^^^^^^ expected &amp;str, found usize
490+
| ^^^^^^^^^^^^ expected `&amp;str`, found `usize`
473491
| (&amp;str型を予期しましたが、usizeが見つかりました)
474-
|
475-
= note: expected type `&amp;str`
476-
found type `usize`
492+
493+
For more information about this error, try `rustc --explain E0308`.
494+
error: could not compile `variables` due to previous error
477495
</code></pre>
478496
<!--
479497
Now that we’ve explored how variables work, let’s look at more data types they

docs/ch03-02-data-types.html

Lines changed: 88 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,18 @@ <h2 id="データ型"><a class="header" href="#データ型">データ型</a></h
182182
-->
183183
<p>ここで型注釈を付けなければ、コンパイラは以下のエラーを表示し、これは可能性のある型のうち、
184184
どの型を使用したいのかを知るのに、コンパイラがプログラマからもっと情報を得る必要があることを意味します:</p>
185-
<pre><code class="language-text">error[E0282]: type annotations needed
185+
<pre><code class="language-console">$ cargo build
186+
Compiling no_type_annotations v0.1.0 (file:///projects/no_type_annotations)
187+
error[E0282]: type annotations needed
186188
(型注釈が必要です)
187189
--&gt; src/main.rs:2:9
188190
|
189191
2 | let guess = &quot;42&quot;.parse().expect(&quot;Not a number!&quot;);
190-
| ^^^^^ cannot infer type for `_`
191-
| (`_`の型が推論できません)
192-
|
193-
= note: type annotations or generic parameter binding required
194-
(注釈: 型注釈、またはジェネリクス引数束縛が必要です)
192+
| ^^^^^ consider giving `guess` a type
193+
| (`guess`に型を与えることを検討してください)
194+
195+
For more information about this error, try `rustc --explain E0282`.
196+
error: could not compile `no_type_annotations` due to previous error
195197
</code></pre>
196198
<!--
197199
You’ll see different type annotations for other data types.
@@ -369,39 +371,26 @@ <h4 id="数値演算"><a class="header" href="#数値演算">数値演算</a></h
369371
<span class="filename">Filename: src/main.rs</span>
370372
-->
371373
<p><span class="filename">ファイル名: src/main.rs</span></p>
372-
<!--
373-
```rust
374-
fn main() {
375-
// addition
376-
let sum = 5 + 10;
377-
378-
// subtraction
379-
let difference = 95.5 - 4.3;
380-
381-
// multiplication
382-
let product = 4 * 30;
383-
384-
// division
385-
let quotient = 56.7 / 32.2;
386-
387-
// remainder
388-
let remainder = 43 % 5;
389-
}
390-
```
391-
-->
392374
<pre><pre class="playground"><code class="language-rust">fn main() {
375+
// addition
393376
// 足し算
394377
let sum = 5 + 10;
395378

379+
// subtraction
396380
// 引き算
397381
let difference = 95.5 - 4.3;
398382

383+
// multiplication
399384
// 掛け算
400385
let product = 4 * 30;
401386

387+
// division
402388
// 割り算
403389
let quotient = 56.7 / 32.2;
390+
let floored = 2 / 3; // Results in 0
391+
// 結果は0
404392

393+
// remainder
405394
// 余り
406395
let remainder = 43 % 5;
407396
}
@@ -429,18 +418,11 @@ <h4 id="論理値型"><a class="header" href="#論理値型">論理値型</a></h
429418
<span class="filename">Filename: src/main.rs</span>
430419
-->
431420
<p><span class="filename">ファイル名: src/main.rs</span></p>
432-
<!--
433-
```rust
434-
fn main() {
435-
let t = true;
436-
let f: bool = false; // with explicit type annotation
437-
}
438-
```
439-
-->
440421
<pre><pre class="playground"><code class="language-rust">fn main() {
441422
let t = true;
442423

443-
let f: bool = false; // 明示的型注釈付きで
424+
let f: bool = false; // with explicit type annotation
425+
// 明示的型注釈付きで
444426
}
445427
</code></pre></pre>
446428
<!--
@@ -637,6 +619,40 @@ <h4 id="配列型"><a class="header" href="#配列型">配列型</a></h4>
637619
<span class="boring">}
638620
</span></code></pre></pre>
639621
<!--
622+
You write an array’s type using square brackets with the type of each element,
623+
a semicolon, and then the number of elements in the array, like so:
624+
-->
625+
<p>例えば次のように、配列の型は角かっこの中に要素の型とセミコロン、そして配列の要素数を与えます。</p>
626+
<pre><pre class="playground"><code class="language-rust">
627+
<span class="boring">#![allow(unused)]
628+
</span><span class="boring">fn main() {
629+
</span>let a: [i32; 5] = [1, 2, 3, 4, 5];
630+
<span class="boring">}
631+
</span></code></pre></pre>
632+
<!--
633+
Here, `i32` is the type of each element. After the semicolon, the number `5`
634+
indicates the array contains five elements.
635+
-->
636+
<p>ここでの<code>i32</code>は要素の型です。セミコロンのあとの<code>5</code>という数字は配列の要素が5つあることを表しています。</p>
637+
<!--
638+
You can also initialize an array to contain the same value for each element by
639+
specifying the initial value, followed by a semicolon, and then the length of
640+
the array in square brackets, as shown here:
641+
-->
642+
<p>次のように、角かっこの中に初期値とセミコロン、そして配列の長さを与えることで、各要素に同じ値を持つように配列を初期化することができます。</p>
643+
<pre><pre class="playground"><code class="language-rust">
644+
<span class="boring">#![allow(unused)]
645+
</span><span class="boring">fn main() {
646+
</span>let a = [3; 5];
647+
<span class="boring">}
648+
</span></code></pre></pre>
649+
<!--
650+
The array named `a` will contain `5` elements that will all be set to the value
651+
`3` initially. This is the same as writing `let a = [3, 3, 3, 3, 3];` but in a
652+
more concise way.
653+
-->
654+
<p>この<code>a</code>という名前の配列は<code>3</code>という値が5つあるものです。これは<code>let a = [3, 3, 3, 3, 3];</code>と書くのと同じですが、より簡潔になります。</p>
655+
<!--
640656
##### Accessing Array Elements
641657
-->
642658
<h5 id="配列の要素にアクセスする"><a class="header" href="#配列の要素にアクセスする">配列の要素にアクセスする</a></h5>
@@ -679,28 +695,52 @@ <h5 id="配列要素への無効なアクセス"><a class="header" href="#配列
679695
<span class="filename">Filename: src/main.rs</span>
680696
-->
681697
<p><span class="filename">ファイル名: src/main.rs</span></p>
682-
<pre><code class="language-rust ignore">fn main() {
698+
<pre><code class="language-rust ignore panics">use std::io;
699+
700+
fn main() {
683701
let a = [1, 2, 3, 4, 5];
684-
let index = 10;
702+
703+
println!(&quot;Please enter an array index.&quot;);
704+
// 配列の何番目の要素にアクセスするか指定してください
705+
706+
let mut index = String::new();
707+
708+
io::stdin()
709+
.read_line(&amp;mut index)
710+
.expect(&quot;Failed to read line&quot;);
711+
// 値の読み込みに失敗しました
712+
713+
let index: usize = index
714+
.trim()
715+
.parse()
716+
.expect(&quot;Index entered was not a number&quot;);
717+
   // 入力された値は数字ではありません
685718

686719
let element = a[index];
687720

688-
println!(&quot;The value of element is: {}&quot;, element); // 要素の値は{}です
721+
println!(
722+
&quot;The value of the element at index {} is: {}&quot;,
723+
// {}番目の要素の値は{}です
724+
index, element
725+
);
689726
}
690727
</code></pre>
691728
<!--
692-
Running this code using `cargo run` produces the following result:
729+
This code compiles successfully. If you run this code using `cargo run` and
730+
enter 0, 1, 2, 3, or 4, the program will print out the corresponding value at
731+
that index in the array. If you instead enter a number past the end of the
732+
array, such as 10, you’ll see output like this:
733+
-->
734+
<p>このコードはコンパイルされます。<code>cargo run</code>で走らせ、0, 1, 2, 3, または4をこのプログラムに入力すると配列の対応する値を出力します。もし配列の末尾を超えるような、例えば10などの数字を与えると、次のような出力が表示されます。</p>
735+
<!-- manual-regeneration
736+
cd listings/ch03-common-programming-concepts/no-listing-15-invalid-array-access
737+
cargo run
738+
10
693739
-->
694-
<p>このコードを<code>cargo run</code>で走らせると、以下のような結果になります:</p>
695-
<pre><code class="language-text">$ cargo run
696-
Compiling arrays v0.1.0 (file:///projects/arrays)
697-
Finished dev [unoptimized + debuginfo] target(s) in 0.31 secs
698-
Running `target/debug/arrays`
699-
thread '&lt;main&gt;' panicked at 'index out of bounds: the len is 5 but the index is
700-
10', src/main.rs:6
701-
スレッド'&lt;main&gt;'は'範囲外アクセス: 長さは5ですが、添え字は10でした', src/main.rs:6
740+
<pre><code class="language-console">thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 10', src/main.rs:19:19
741+
スレッド'main'は'範囲外アクセス: 長さは5ですが、添え字は10でした', src/main.rs:19:19
702742
でパニックしました
703-
note: Run with `RUST_BACKTRACE=1` for a backtrace.
743+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
704744
</code></pre>
705745
<!--
706746
The compilation didn’t produce any errors, but the program results in a

0 commit comments

Comments
 (0)