mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-01-22 23:10:20 +08:00
Add English Version
This commit is contained in:
parent
53b811b041
commit
8f6d3ad5e9
8
english/book.toml
Normal file
8
english/book.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[book]
|
||||
title = "The Rust Programming Language"
|
||||
author = "Steve Klabnik and Carol Nichols, with Contributions from the Rust Community"
|
||||
|
||||
[output.html]
|
||||
additional-css = ["ferris.css", "theme/2018-edition.css"]
|
||||
additional-js = ["ferris.js", "language.js"]
|
||||
git-repository-url = "https://github.com/rust-lang/book"
|
26
english/dot/trpl04-01.dot
Normal file
26
english/dot/trpl04-01.dot
Normal file
@ -0,0 +1,26 @@
|
||||
digraph {
|
||||
rankdir=LR;
|
||||
overlap=false;
|
||||
dpi=300.0;
|
||||
node [shape="plaintext"];
|
||||
|
||||
table0[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">s1</TD></TR>
|
||||
<TR><TD>name</TD><TD>value</TD></TR>
|
||||
<TR><TD>ptr</TD><TD PORT="pointer"></TD></TR>
|
||||
<TR><TD>len</TD><TD>5</TD></TR>
|
||||
<TR><TD>capacity</TD><TD>5</TD></TR>
|
||||
</TABLE>>];
|
||||
table1[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD>index</TD><TD>value</TD></TR>
|
||||
<TR><TD PORT="pointee">0</TD><TD>h</TD></TR>
|
||||
<TR><TD>1</TD><TD>e</TD></TR>
|
||||
<TR><TD>2</TD><TD>l</TD></TR>
|
||||
<TR><TD>3</TD><TD>l</TD></TR>
|
||||
<TR><TD>4</TD><TD>o</TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
edge[tailclip="false"];
|
||||
table0:pointer:c -> table1:pointee;
|
||||
}
|
||||
|
35
english/dot/trpl04-02.dot
Normal file
35
english/dot/trpl04-02.dot
Normal file
@ -0,0 +1,35 @@
|
||||
digraph {
|
||||
rankdir=LR;
|
||||
overlap=false;
|
||||
dpi=300.0;
|
||||
node [shape="plaintext"];
|
||||
|
||||
table0[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">s1</TD></TR>
|
||||
<TR><TD>name</TD><TD>value</TD></TR>
|
||||
<TR><TD>ptr</TD><TD PORT="pointer"></TD></TR>
|
||||
<TR><TD>len</TD><TD>5</TD></TR>
|
||||
<TR><TD>capacity</TD><TD>5</TD></TR>
|
||||
</TABLE>>];
|
||||
table3[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">s2</TD></TR>
|
||||
<TR><TD>name</TD><TD>value</TD></TR>
|
||||
<TR><TD>ptr</TD><TD PORT="pointer"></TD></TR>
|
||||
<TR><TD>len</TD><TD>5</TD></TR>
|
||||
<TR><TD>capacity</TD><TD>5</TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
table1[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD>index</TD><TD>value</TD></TR>
|
||||
<TR><TD PORT="pointee">0</TD><TD>h</TD></TR>
|
||||
<TR><TD>1</TD><TD>e</TD></TR>
|
||||
<TR><TD>2</TD><TD>l</TD></TR>
|
||||
<TR><TD>3</TD><TD>l</TD></TR>
|
||||
<TR><TD>4</TD><TD>o</TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
edge[tailclip="false"];
|
||||
table0:pointer:c -> table1:pointee;
|
||||
table3:pointer:c -> table1:pointee;
|
||||
}
|
||||
|
44
english/dot/trpl04-03.dot
Normal file
44
english/dot/trpl04-03.dot
Normal file
@ -0,0 +1,44 @@
|
||||
digraph {
|
||||
rankdir=LR;
|
||||
overlap=false;
|
||||
dpi=300.0;
|
||||
node [shape="plaintext"];
|
||||
|
||||
table0[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">s2</TD></TR>
|
||||
<TR><TD>name</TD><TD>value</TD></TR>
|
||||
<TR><TD>ptr</TD><TD PORT="pointer"></TD></TR>
|
||||
<TR><TD>len</TD><TD>5</TD></TR>
|
||||
<TR><TD>capacity</TD><TD>5</TD></TR>
|
||||
</TABLE>>];
|
||||
table1[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD>index</TD><TD>value</TD></TR>
|
||||
<TR><TD PORT="pointee">0</TD><TD>h</TD></TR>
|
||||
<TR><TD>1</TD><TD>e</TD></TR>
|
||||
<TR><TD>2</TD><TD>l</TD></TR>
|
||||
<TR><TD>3</TD><TD>l</TD></TR>
|
||||
<TR><TD>4</TD><TD>o</TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
table3[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">s1</TD></TR>
|
||||
<TR><TD>name</TD><TD>value</TD></TR>
|
||||
<TR><TD>ptr</TD><TD PORT="pointer"></TD></TR>
|
||||
<TR><TD>len</TD><TD>5</TD></TR>
|
||||
<TR><TD>capacity</TD><TD>5</TD></TR>
|
||||
</TABLE>>];
|
||||
table4[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD>index</TD><TD>value</TD></TR>
|
||||
<TR><TD PORT="pointee">0</TD><TD>h</TD></TR>
|
||||
<TR><TD>1</TD><TD>e</TD></TR>
|
||||
<TR><TD>2</TD><TD>l</TD></TR>
|
||||
<TR><TD>3</TD><TD>l</TD></TR>
|
||||
<TR><TD>4</TD><TD>o</TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
|
||||
edge[tailclip="false"];
|
||||
table0:pointer:c -> table1:pointee;
|
||||
table3:pointer:c -> table4:pointee;
|
||||
}
|
||||
|
35
english/dot/trpl04-04.dot
Normal file
35
english/dot/trpl04-04.dot
Normal file
@ -0,0 +1,35 @@
|
||||
digraph {
|
||||
rankdir=LR;
|
||||
overlap=false;
|
||||
dpi=300.0;
|
||||
node [shape="plaintext"];
|
||||
|
||||
table0[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
|
||||
<TR><TD COLSPAN="2" SIDES="B">s1</TD></TR>
|
||||
<TR><TD>name</TD><TD>value</TD></TR>
|
||||
<TR><TD>ptr</TD><TD PORT="pointer"></TD></TR>
|
||||
<TR><TD>len</TD><TD>5</TD></TR>
|
||||
<TR><TD>capacity</TD><TD>5</TD></TR>
|
||||
</TABLE>>];
|
||||
table3[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">s2</TD></TR>
|
||||
<TR><TD>name</TD><TD>value</TD></TR>
|
||||
<TR><TD>ptr</TD><TD PORT="pointer"></TD></TR>
|
||||
<TR><TD>len</TD><TD>5</TD></TR>
|
||||
<TR><TD>capacity</TD><TD>5</TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
table1[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD>index</TD><TD>value</TD></TR>
|
||||
<TR><TD PORT="pointee">0</TD><TD>h</TD></TR>
|
||||
<TR><TD>1</TD><TD>e</TD></TR>
|
||||
<TR><TD>2</TD><TD>l</TD></TR>
|
||||
<TR><TD>3</TD><TD>l</TD></TR>
|
||||
<TR><TD>4</TD><TD>o</TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
edge[tailclip="false"];
|
||||
table0:pointer:c -> table1:pointee;
|
||||
table3:pointer:c -> table1:pointee;
|
||||
}
|
||||
|
32
english/dot/trpl04-05.dot
Normal file
32
english/dot/trpl04-05.dot
Normal file
@ -0,0 +1,32 @@
|
||||
digraph {
|
||||
rankdir=LR;
|
||||
overlap=false;
|
||||
dpi=300.0;
|
||||
node [shape="plaintext"];
|
||||
|
||||
table0[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">s</TD></TR>
|
||||
<TR><TD>name</TD><TD>value</TD></TR>
|
||||
<TR><TD>ptr</TD><TD PORT="borrower"></TD></TR>
|
||||
</TABLE>>];
|
||||
table1[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">s1</TD></TR>
|
||||
<TR><TD>name</TD><TD>value</TD></TR>
|
||||
<TR><TD PORT="borrowee">ptr</TD><TD PORT="pointer"></TD></TR>
|
||||
<TR><TD>len</TD><TD>5</TD></TR>
|
||||
<TR><TD>capacity</TD><TD>5</TD></TR>
|
||||
</TABLE>>];
|
||||
table2[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD>index</TD><TD>value</TD></TR>
|
||||
<TR><TD PORT="pointee">0</TD><TD>h</TD></TR>
|
||||
<TR><TD>1</TD><TD>e</TD></TR>
|
||||
<TR><TD>2</TD><TD>l</TD></TR>
|
||||
<TR><TD>3</TD><TD>l</TD></TR>
|
||||
<TR><TD>4</TD><TD>o</TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
edge[tailclip="false"];
|
||||
table1:pointer:c -> table2:pointee;
|
||||
table0:borrower:c -> table1:borrowee;
|
||||
}
|
||||
|
41
english/dot/trpl04-06.dot
Normal file
41
english/dot/trpl04-06.dot
Normal file
@ -0,0 +1,41 @@
|
||||
digraph {
|
||||
rankdir=LR;
|
||||
overlap=false;
|
||||
dpi=300.0;
|
||||
node [shape="plaintext"];
|
||||
|
||||
table0[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">world</TD></TR>
|
||||
<TR><TD>name</TD><TD>value</TD></TR>
|
||||
<TR><TD>ptr</TD><TD PORT="pointer2"></TD></TR>
|
||||
<TR><TD>len</TD><TD>5</TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
table3[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">s</TD></TR>
|
||||
<TR><TD>name</TD><TD>value</TD></TR>
|
||||
<TR><TD>ptr</TD><TD PORT="pointer"></TD></TR>
|
||||
<TR><TD>len</TD><TD>11</TD></TR>
|
||||
<TR><TD>capacity</TD><TD>11</TD></TR>
|
||||
</TABLE>>];
|
||||
table4[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD>index</TD><TD>value</TD></TR>
|
||||
<TR><TD PORT="pointee">0</TD><TD>h</TD></TR>
|
||||
<TR><TD>1</TD><TD>e</TD></TR>
|
||||
<TR><TD>2</TD><TD>l</TD></TR>
|
||||
<TR><TD>3</TD><TD>l</TD></TR>
|
||||
<TR><TD>4</TD><TD>o</TD></TR>
|
||||
<TR><TD>5</TD><TD> </TD></TR>
|
||||
<TR><TD PORT="pointee2">6</TD><TD>w</TD></TR>
|
||||
<TR><TD>7</TD><TD>o</TD></TR>
|
||||
<TR><TD>8</TD><TD>r</TD></TR>
|
||||
<TR><TD>9</TD><TD>l</TD></TR>
|
||||
<TR><TD>10</TD><TD>d</TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
|
||||
edge[tailclip="false"];
|
||||
table0:pointer2:c -> table4:pointee2;
|
||||
table3:pointer:c -> table4:pointee;
|
||||
}
|
||||
|
24
english/dot/trpl15-01.dot
Normal file
24
english/dot/trpl15-01.dot
Normal file
@ -0,0 +1,24 @@
|
||||
digraph {
|
||||
rankdir=LR;
|
||||
overlap=false;
|
||||
dpi=300.0;
|
||||
node [shape="plaintext"];
|
||||
|
||||
table0[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">Cons</TD></TR>
|
||||
<TR><TD>i32</TD><TD><TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">Cons</TD></TR>
|
||||
<TR><TD>i32</TD><TD><TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">Cons</TD></TR>
|
||||
<TR><TD>i32</TD><TD><TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">Cons</TD></TR>
|
||||
<TR><TD>i32</TD><TD><TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">Cons</TD></TR>
|
||||
<TR><TD>i32</TD><TD>∞</TD></TR>
|
||||
</TABLE></TD></TR>
|
||||
</TABLE></TD></TR>
|
||||
</TABLE></TD></TR>
|
||||
</TABLE></TD></TR>
|
||||
</TABLE>>];
|
||||
}
|
||||
|
18
english/dot/trpl15-02.dot
Normal file
18
english/dot/trpl15-02.dot
Normal file
@ -0,0 +1,18 @@
|
||||
digraph {
|
||||
rankdir=LR;
|
||||
overlap=false;
|
||||
dpi=300.0;
|
||||
node [shape="plaintext"];
|
||||
|
||||
table0[label=<
|
||||
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" SIDES="B">Cons</TD></TR>
|
||||
<TR><TD>i32</TD><TD>
|
||||
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD SIDES="B">Box</TD></TR>
|
||||
<TR><TD>usize</TD></TR>
|
||||
</TABLE>
|
||||
</TD></TR>
|
||||
</TABLE>>];
|
||||
}
|
||||
|
51
english/dot/trpl15-03.dot
Normal file
51
english/dot/trpl15-03.dot
Normal file
@ -0,0 +1,51 @@
|
||||
digraph {
|
||||
rankdir=LR;
|
||||
overlap=false;
|
||||
dpi=300.0;
|
||||
node [shape="plaintext"];
|
||||
|
||||
table4[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD SIDES="B">b</TD><TD SIDES="B" PORT="ptr4"></TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
table5[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD PORT="pte4">3</TD><TD PORT="ptr5"> </TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
|
||||
table0[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD SIDES="B">a</TD><TD SIDES="B" PORT="ptr0"></TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
table1[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD PORT="pte0">5</TD><TD PORT="ptr1"> </TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
table2[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD PORT="pte1">10</TD><TD PORT="ptr2"> </TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
table3[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD PORT="pte2">Nil</TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
|
||||
table6[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD SIDES="B">c</TD><TD SIDES="B" PORT="ptr6"></TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
table7[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
|
||||
<TR><TD PORT="pte6">4</TD><TD PORT="ptr7"> </TD></TR>
|
||||
</TABLE>>];
|
||||
|
||||
|
||||
edge[tailclip="false"];
|
||||
table0:ptr0:c -> table1:pte0;
|
||||
table1:ptr1:c -> table2:pte1;
|
||||
table2:ptr2:c -> table3:pte2;
|
||||
table4:ptr4:c -> table5:pte4;
|
||||
table5:ptr5:c -> table1:pte0;
|
||||
table6:ptr6:c -> table7:pte6;
|
||||
table7:ptr7:c -> table1:pte0;
|
||||
}
|
||||
|
16
english/dot/trpl15-04.dot
Normal file
16
english/dot/trpl15-04.dot
Normal file
@ -0,0 +1,16 @@
|
||||
digraph {
|
||||
node[shape=record];
|
||||
rankdir=LR;
|
||||
|
||||
l1[label="{<data> 5| <next>}"];
|
||||
l2[label="{<data> 10| <next>}"];
|
||||
|
||||
{node[shape=point height=0] invisible_start invisible_end}
|
||||
|
||||
a -> l1:n;
|
||||
b -> l2:n;
|
||||
invisible_start:n -> l1[arrowtail=none];
|
||||
invisible_start:s -> invisible_end:s[dir=none];
|
||||
l1:next:c -> l2:data;
|
||||
l2:next:c -> invisible_end:n[arrowhead=none];
|
||||
}
|
33
english/ferris.css
Normal file
33
english/ferris.css
Normal file
@ -0,0 +1,33 @@
|
||||
body.light .does_not_compile,
|
||||
body.light .panics,
|
||||
body.light .not_desired_behavior,
|
||||
body.rust .does_not_compile,
|
||||
body.rust .panics,
|
||||
body.rust .not_desired_behavior {
|
||||
background: #fff1f1;
|
||||
}
|
||||
|
||||
body.coal .does_not_compile,
|
||||
body.coal .panics,
|
||||
body.coal .not_desired_behavior,
|
||||
body.navy .does_not_compile,
|
||||
body.navy .panics,
|
||||
body.navy .not_desired_behavior,
|
||||
body.ayu .does_not_compile,
|
||||
body.ayu .panics,
|
||||
body.ayu .not_desired_behavior {
|
||||
background: #501f21;
|
||||
}
|
||||
|
||||
.ferris {
|
||||
position: absolute;
|
||||
z-index: 99;
|
||||
right: 5px;
|
||||
top: 30px;
|
||||
width: 10%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.ferris-explain {
|
||||
width: 100px;
|
||||
}
|
51
english/ferris.js
Normal file
51
english/ferris.js
Normal file
@ -0,0 +1,51 @@
|
||||
var ferrisTypes = [
|
||||
{
|
||||
attr: 'does_not_compile',
|
||||
title: 'This code does not compile!'
|
||||
},
|
||||
{
|
||||
attr: 'panics',
|
||||
title: 'This code panics!'
|
||||
},
|
||||
{
|
||||
attr: 'unsafe',
|
||||
title: 'This code block contains unsafe code.'
|
||||
},
|
||||
{
|
||||
attr: 'not_desired_behavior',
|
||||
title: 'This code does not produce the desired behavior.'
|
||||
}
|
||||
]
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
for (var ferrisType of ferrisTypes) {
|
||||
attachFerrises(ferrisType)
|
||||
}
|
||||
})
|
||||
|
||||
function attachFerrises (type) {
|
||||
var elements = document.getElementsByClassName(type.attr)
|
||||
|
||||
for (var codeBlock of elements) {
|
||||
var lines = codeBlock.textContent.split(/\r|\r\n|\n/).length - 1;
|
||||
|
||||
if (lines >= 4) {
|
||||
attachFerris(codeBlock, type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function attachFerris (element, type) {
|
||||
var a = document.createElement('a')
|
||||
a.setAttribute('href', 'ch00-00-introduction.html#ferris')
|
||||
a.setAttribute('target', '_blank')
|
||||
|
||||
var img = document.createElement('img')
|
||||
img.setAttribute('src', 'img/ferris/' + type.attr + '.svg')
|
||||
img.setAttribute('title', type.title)
|
||||
img.className = 'ferris'
|
||||
|
||||
a.appendChild(img)
|
||||
|
||||
element.parentElement.insertBefore(a, element)
|
||||
}
|
33
english/language.js
Normal file
33
english/language.js
Normal file
@ -0,0 +1,33 @@
|
||||
(function () {
|
||||
var url = window.location.href;
|
||||
var host = window.location.host;
|
||||
|
||||
var search = {
|
||||
en: "/en/",
|
||||
zh_CN: "/zh-CN/"
|
||||
}
|
||||
|
||||
var replaceWith = {
|
||||
en: "/zh-CN/",
|
||||
zh_CN: "/en/"
|
||||
}
|
||||
|
||||
|
||||
var link = "";
|
||||
var word = "";
|
||||
|
||||
if (url.indexOf(search.en) != -1 && url.indexOf(search.en) === (url.indexOf(host) + host.length)) {
|
||||
link = url.replace(search.en, replaceWith.en);
|
||||
word = "简体中文";
|
||||
} else if (url.indexOf(search.zh_CN) != -1 && url.indexOf(search.zh_CN) === (url.indexOf(host) + host.length)) {
|
||||
link = url.replace(search.zh_CN, replaceWith.zh_CN);
|
||||
word = "English";
|
||||
}
|
||||
|
||||
var node = '<a href="' + link + '"><i id="print-button" class="fa fa-language"> ' + word + '</i></a>';
|
||||
var insertNode = document.getElementsByClassName('right-buttons');
|
||||
if (insertNode.length > 0 && link != "") {
|
||||
var html = insertNode[0].innerHTML;
|
||||
insertNode[0].innerHTML = html + node;
|
||||
}
|
||||
})()
|
6
english/listings/ch02-guessing-game-tutorial/listing-02-01/Cargo.lock
generated
Normal file
6
english/listings/ch02-guessing-game-tutorial/listing-02-01/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,31 @@
|
||||
// ANCHOR: all
|
||||
// ANCHOR: io
|
||||
use std::io;
|
||||
// ANCHOR_END: io
|
||||
|
||||
// ANCHOR: main
|
||||
fn main() {
|
||||
// ANCHOR_END: main
|
||||
// ANCHOR: print
|
||||
println!("Guess the number!");
|
||||
|
||||
println!("Please input your guess.");
|
||||
// ANCHOR_END: print
|
||||
|
||||
// ANCHOR: string
|
||||
let mut guess = String::new();
|
||||
// ANCHOR_END: string
|
||||
|
||||
// ANCHOR: read
|
||||
io::stdin()
|
||||
.read_line(&mut guess)
|
||||
// ANCHOR_END: read
|
||||
// ANCHOR: expect
|
||||
.expect("Failed to read line");
|
||||
// ANCHOR_END: expect
|
||||
|
||||
// ANCHOR: print_guess
|
||||
println!("You guessed: {}", guess);
|
||||
// ANCHOR_END: print_guess
|
||||
}
|
||||
// ANCHOR: all
|
83
english/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock
generated
Normal file
83
english/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock
generated
Normal file
@ -0,0 +1,83 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.3"
|
@ -0,0 +1,15 @@
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
println!("Guess the number!");
|
||||
|
||||
println!("Please input your guess.");
|
||||
|
||||
let mut guess = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut guess)
|
||||
.expect("Failed to read line");
|
||||
|
||||
println!("You guessed: {}", guess);
|
||||
}
|
83
english/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.lock
generated
Normal file
83
english/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.lock
generated
Normal file
@ -0,0 +1,83 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.3"
|
@ -0,0 +1,28 @@
|
||||
// ANCHOR: all
|
||||
use std::io;
|
||||
// ANCHOR: ch07-04
|
||||
use rand::Rng;
|
||||
|
||||
fn main() {
|
||||
// ANCHOR_END: ch07-04
|
||||
println!("Guess the number!");
|
||||
|
||||
// ANCHOR: ch07-04
|
||||
let secret_number = rand::thread_rng().gen_range(1..101);
|
||||
// ANCHOR_END: ch07-04
|
||||
|
||||
println!("The secret number is: {}", secret_number);
|
||||
|
||||
println!("Please input your guess.");
|
||||
|
||||
let mut guess = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut guess)
|
||||
.expect("Failed to read line");
|
||||
|
||||
println!("You guessed: {}", guess);
|
||||
// ANCHOR: ch07-04
|
||||
}
|
||||
// ANCHOR_END: ch07-04
|
||||
// ANCHOR_END: all
|
83
english/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.lock
generated
Normal file
83
english/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.lock
generated
Normal file
@ -0,0 +1,83 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.3"
|
@ -0,0 +1,24 @@
|
||||
$ cargo build
|
||||
Compiling libc v0.2.86
|
||||
Compiling getrandom v0.2.2
|
||||
Compiling cfg-if v1.0.0
|
||||
Compiling ppv-lite86 v0.2.10
|
||||
Compiling rand_core v0.6.2
|
||||
Compiling rand_chacha v0.3.0
|
||||
Compiling rand v0.8.3
|
||||
Compiling guessing_game v0.1.0 (file:///projects/guessing_game)
|
||||
error[E0308]: mismatched types
|
||||
--> src/main.rs:22:21
|
||||
|
|
||||
22 | match guess.cmp(&secret_number) {
|
||||
| ^^^^^^^^^^^^^^ expected struct `String`, found integer
|
||||
|
|
||||
= note: expected reference `&String`
|
||||
found reference `&{integer}`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
error: could not compile `guessing_game`
|
||||
|
||||
To learn more, run the command again with --verbose.
|
@ -0,0 +1,32 @@
|
||||
// ANCHOR: here
|
||||
use rand::Rng;
|
||||
use std::cmp::Ordering;
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
// --snip--
|
||||
// ANCHOR_END: here
|
||||
println!("Guess the number!");
|
||||
|
||||
let secret_number = rand::thread_rng().gen_range(1..101);
|
||||
|
||||
println!("The secret number is: {}", secret_number);
|
||||
|
||||
println!("Please input your guess.");
|
||||
|
||||
let mut guess = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut guess)
|
||||
.expect("Failed to read line");
|
||||
// ANCHOR: here
|
||||
|
||||
println!("You guessed: {}", guess);
|
||||
|
||||
match guess.cmp(&secret_number) {
|
||||
Ordering::Less => println!("Too small!"),
|
||||
Ordering::Greater => println!("Too big!"),
|
||||
Ordering::Equal => println!("You win!"),
|
||||
}
|
||||
}
|
||||
// ANCHOR_END: here
|
83
english/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.lock
generated
Normal file
83
english/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.lock
generated
Normal file
@ -0,0 +1,83 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.3"
|
@ -0,0 +1,45 @@
|
||||
use rand::Rng;
|
||||
use std::cmp::Ordering;
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
println!("Guess the number!");
|
||||
|
||||
let secret_number = rand::thread_rng().gen_range(1..101);
|
||||
|
||||
println!("The secret number is: {}", secret_number);
|
||||
|
||||
loop {
|
||||
println!("Please input your guess.");
|
||||
|
||||
let mut guess = String::new();
|
||||
|
||||
// ANCHOR: here
|
||||
// --snip--
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut guess)
|
||||
.expect("Failed to read line");
|
||||
|
||||
// ANCHOR: ch19
|
||||
let guess: u32 = match guess.trim().parse() {
|
||||
Ok(num) => num,
|
||||
Err(_) => continue,
|
||||
};
|
||||
// ANCHOR_END: ch19
|
||||
|
||||
println!("You guessed: {}", guess);
|
||||
|
||||
// --snip--
|
||||
// ANCHOR_END: here
|
||||
|
||||
match guess.cmp(&secret_number) {
|
||||
Ordering::Less => println!("Too small!"),
|
||||
Ordering::Greater => println!("Too big!"),
|
||||
Ordering::Equal => {
|
||||
println!("You win!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
83
english/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.lock
generated
Normal file
83
english/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.lock
generated
Normal file
@ -0,0 +1,83 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.3"
|
@ -0,0 +1,35 @@
|
||||
use rand::Rng;
|
||||
use std::cmp::Ordering;
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
println!("Guess the number!");
|
||||
|
||||
let secret_number = rand::thread_rng().gen_range(1..101);
|
||||
|
||||
loop {
|
||||
println!("Please input your guess.");
|
||||
|
||||
let mut guess = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut guess)
|
||||
.expect("Failed to read line");
|
||||
|
||||
let guess: u32 = match guess.trim().parse() {
|
||||
Ok(num) => num,
|
||||
Err(_) => continue,
|
||||
};
|
||||
|
||||
println!("You guessed: {}", guess);
|
||||
|
||||
match guess.cmp(&secret_number) {
|
||||
Ordering::Less => println!("Too small!"),
|
||||
Ordering::Greater => println!("Too big!"),
|
||||
Ordering::Equal => {
|
||||
println!("You win!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
6
english/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.lock
generated
Normal file
6
english/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,5 @@
|
||||
$ cargo run
|
||||
Compiling guessing_game v0.1.0 (file:///projects/guessing_game)
|
||||
Finished dev [unoptimized + debuginfo] target(s) in 1.50s
|
||||
Running `target/debug/guessing_game`
|
||||
Hello, world!
|
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
6
english/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/Cargo.lock
generated
Normal file
6
english/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,14 @@
|
||||
$ cargo build
|
||||
Compiling guessing_game v0.1.0 (file:///projects/guessing_game)
|
||||
warning: unused `Result` that must be used
|
||||
--> src/main.rs:10:5
|
||||
|
|
||||
10 | io::stdin().read_line(&mut guess);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(unused_must_use)]` on by default
|
||||
= note: this `Result` may be an `Err` variant, which should be handled
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
Finished dev [unoptimized + debuginfo] target(s) in 0.59s
|
@ -0,0 +1,13 @@
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
println!("Guess the number!");
|
||||
|
||||
println!("Please input your guess.");
|
||||
|
||||
let mut guess = String::new();
|
||||
|
||||
io::stdin().read_line(&mut guess);
|
||||
|
||||
println!("You guessed: {}", guess);
|
||||
}
|
83
english/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.lock
generated
Normal file
83
english/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.lock
generated
Normal file
@ -0,0 +1,83 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.3"
|
@ -0,0 +1,33 @@
|
||||
use rand::Rng;
|
||||
use std::cmp::Ordering;
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
println!("Guess the number!");
|
||||
|
||||
let secret_number = rand::thread_rng().gen_range(1..101);
|
||||
|
||||
println!("The secret number is: {}", secret_number);
|
||||
|
||||
println!("Please input your guess.");
|
||||
|
||||
// ANCHOR: here
|
||||
// --snip--
|
||||
|
||||
let mut guess = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut guess)
|
||||
.expect("Failed to read line");
|
||||
|
||||
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
||||
|
||||
println!("You guessed: {}", guess);
|
||||
|
||||
match guess.cmp(&secret_number) {
|
||||
Ordering::Less => println!("Too small!"),
|
||||
Ordering::Greater => println!("Too big!"),
|
||||
Ordering::Equal => println!("You win!"),
|
||||
}
|
||||
// ANCHOR_END: here
|
||||
}
|
83
english/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.lock
generated
Normal file
83
english/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.lock
generated
Normal file
@ -0,0 +1,83 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.3"
|
@ -0,0 +1,40 @@
|
||||
use rand::Rng;
|
||||
use std::cmp::Ordering;
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
println!("Guess the number!");
|
||||
|
||||
let secret_number = rand::thread_rng().gen_range(1..101);
|
||||
|
||||
// ANCHOR: here
|
||||
// --snip--
|
||||
|
||||
println!("The secret number is: {}", secret_number);
|
||||
|
||||
loop {
|
||||
println!("Please input your guess.");
|
||||
|
||||
// --snip--
|
||||
|
||||
// ANCHOR_END: here
|
||||
|
||||
let mut guess = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut guess)
|
||||
.expect("Failed to read line");
|
||||
|
||||
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
||||
|
||||
println!("You guessed: {}", guess);
|
||||
|
||||
// ANCHOR: here
|
||||
match guess.cmp(&secret_number) {
|
||||
Ordering::Less => println!("Too small!"),
|
||||
Ordering::Greater => println!("Too big!"),
|
||||
Ordering::Equal => println!("You win!"),
|
||||
}
|
||||
}
|
||||
}
|
||||
// ANCHOR_END: here
|
83
english/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.lock
generated
Normal file
83
english/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.lock
generated
Normal file
@ -0,0 +1,83 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.3"
|
@ -0,0 +1,38 @@
|
||||
use rand::Rng;
|
||||
use std::cmp::Ordering;
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
println!("Guess the number!");
|
||||
|
||||
let secret_number = rand::thread_rng().gen_range(1..101);
|
||||
|
||||
println!("The secret number is: {}", secret_number);
|
||||
|
||||
loop {
|
||||
println!("Please input your guess.");
|
||||
|
||||
let mut guess = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut guess)
|
||||
.expect("Failed to read line");
|
||||
|
||||
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
||||
|
||||
println!("You guessed: {}", guess);
|
||||
|
||||
// ANCHOR: here
|
||||
// --snip--
|
||||
|
||||
match guess.cmp(&secret_number) {
|
||||
Ordering::Less => println!("Too small!"),
|
||||
Ordering::Greater => println!("Too big!"),
|
||||
Ordering::Equal => {
|
||||
println!("You win!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ANCHOR_END: here
|
6
english/listings/ch03-common-programming-concepts/listing-03-01/Cargo.lock
generated
Normal file
6
english/listings/ch03-common-programming-concepts/listing-03-01/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "functions"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "functions"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
let y = 6;
|
||||
}
|
6
english/listings/ch03-common-programming-concepts/listing-03-02/Cargo.lock
generated
Normal file
6
english/listings/ch03-common-programming-concepts/listing-03-02/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "branches"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "branches"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,5 @@
|
||||
$ cargo run
|
||||
Compiling branches v0.1.0 (file:///projects/branches)
|
||||
Finished dev [unoptimized + debuginfo] target(s) in 0.30s
|
||||
Running `target/debug/branches`
|
||||
The value of number is: 5
|
@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
let condition = true;
|
||||
let number = if condition { 5 } else { 6 };
|
||||
|
||||
println!("The value of number is: {}", number);
|
||||
}
|
6
english/listings/ch03-common-programming-concepts/listing-03-03/Cargo.lock
generated
Normal file
6
english/listings/ch03-common-programming-concepts/listing-03-03/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "loops"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "loops"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,11 @@
|
||||
fn main() {
|
||||
let mut number = 3;
|
||||
|
||||
while number != 0 {
|
||||
println!("{}!", number);
|
||||
|
||||
number -= 1;
|
||||
}
|
||||
|
||||
println!("LIFTOFF!!!");
|
||||
}
|
6
english/listings/ch03-common-programming-concepts/listing-03-04/Cargo.lock
generated
Normal file
6
english/listings/ch03-common-programming-concepts/listing-03-04/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "loops"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "loops"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,9 @@
|
||||
$ cargo run
|
||||
Compiling loops v0.1.0 (file:///projects/loops)
|
||||
Finished dev [unoptimized + debuginfo] target(s) in 0.32s
|
||||
Running `target/debug/loops`
|
||||
the value is: 10
|
||||
the value is: 20
|
||||
the value is: 30
|
||||
the value is: 40
|
||||
the value is: 50
|
@ -0,0 +1,10 @@
|
||||
fn main() {
|
||||
let a = [10, 20, 30, 40, 50];
|
||||
let mut index = 0;
|
||||
|
||||
while index < 5 {
|
||||
println!("the value is: {}", a[index]);
|
||||
|
||||
index += 1;
|
||||
}
|
||||
}
|
6
english/listings/ch03-common-programming-concepts/listing-03-05/Cargo.lock
generated
Normal file
6
english/listings/ch03-common-programming-concepts/listing-03-05/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "loops"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "loops"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
let a = [10, 20, 30, 40, 50];
|
||||
|
||||
for element in a.iter() {
|
||||
println!("the value is: {}", element);
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "variables"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "variables"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,20 @@
|
||||
$ cargo run
|
||||
Compiling variables v0.1.0 (file:///projects/variables)
|
||||
error[E0384]: cannot assign twice to immutable variable `x`
|
||||
--> src/main.rs:4:5
|
||||
|
|
||||
2 | let x = 5;
|
||||
| -
|
||||
| |
|
||||
| first assignment to `x`
|
||||
| help: make this binding mutable: `mut x`
|
||||
3 | println!("The value of x is: {}", x);
|
||||
4 | x = 6;
|
||||
| ^^^^^ cannot assign twice to immutable variable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0384`.
|
||||
error: could not compile `variables`
|
||||
|
||||
To learn more, run the command again with --verbose.
|
@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
let x = 5;
|
||||
println!("The value of x is: {}", x);
|
||||
x = 6;
|
||||
println!("The value of x is: {}", x);
|
||||
}
|
6
english/listings/ch03-common-programming-concepts/no-listing-02-adding-mut/Cargo.lock
generated
Normal file
6
english/listings/ch03-common-programming-concepts/no-listing-02-adding-mut/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "variables"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "variables"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,6 @@
|
||||
$ cargo run
|
||||
Compiling variables v0.1.0 (file:///projects/variables)
|
||||
Finished dev [unoptimized + debuginfo] target(s) in 0.30s
|
||||
Running `target/debug/variables`
|
||||
The value of x is: 5
|
||||
The value of x is: 6
|
@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
let mut x = 5;
|
||||
println!("The value of x is: {}", x);
|
||||
x = 6;
|
||||
println!("The value of x is: {}", x);
|
||||
}
|
6
english/listings/ch03-common-programming-concepts/no-listing-03-shadowing/Cargo.lock
generated
Normal file
6
english/listings/ch03-common-programming-concepts/no-listing-03-shadowing/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "variables"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "variables"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,5 @@
|
||||
$ cargo run
|
||||
Compiling variables v0.1.0 (file:///projects/variables)
|
||||
Finished dev [unoptimized + debuginfo] target(s) in 0.31s
|
||||
Running `target/debug/variables`
|
||||
The value of x is: 12
|
@ -0,0 +1,9 @@
|
||||
fn main() {
|
||||
let x = 5;
|
||||
|
||||
let x = x + 1;
|
||||
|
||||
let x = x * 2;
|
||||
|
||||
println!("The value of x is: {}", x);
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "variables"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "variables"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
// ANCHOR: here
|
||||
let spaces = " ";
|
||||
let spaces = spaces.len();
|
||||
// ANCHOR_END: here
|
||||
}
|
6
english/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/Cargo.lock
generated
Normal file
6
english/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "variables"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "variables"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,14 @@
|
||||
$ cargo run
|
||||
Compiling variables v0.1.0 (file:///projects/variables)
|
||||
error[E0308]: mismatched types
|
||||
--> src/main.rs:3:14
|
||||
|
|
||||
3 | spaces = spaces.len();
|
||||
| ^^^^^^^^^^^^ expected `&str`, found `usize`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
error: could not compile `variables`
|
||||
|
||||
To learn more, run the command again with --verbose.
|
@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
// ANCHOR: here
|
||||
let mut spaces = " ";
|
||||
spaces = spaces.len();
|
||||
// ANCHOR_END: here
|
||||
}
|
6
english/listings/ch03-common-programming-concepts/no-listing-06-floating-point/Cargo.lock
generated
Normal file
6
english/listings/ch03-common-programming-concepts/no-listing-06-floating-point/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "floating-point"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "floating-point"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
let x = 2.0; // f64
|
||||
|
||||
let y: f32 = 3.0; // f32
|
||||
}
|
6
english/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/Cargo.lock
generated
Normal file
6
english/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "numeric-operations"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "numeric-operations"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,16 @@
|
||||
fn main() {
|
||||
// addition
|
||||
let sum = 5 + 10;
|
||||
|
||||
// subtraction
|
||||
let difference = 95.5 - 4.3;
|
||||
|
||||
// multiplication
|
||||
let product = 4 * 30;
|
||||
|
||||
// division
|
||||
let quotient = 56.7 / 32.2;
|
||||
|
||||
// remainder
|
||||
let remainder = 43 % 5;
|
||||
}
|
6
english/listings/ch03-common-programming-concepts/no-listing-08-boolean/Cargo.lock
generated
Normal file
6
english/listings/ch03-common-programming-concepts/no-listing-08-boolean/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "boolean"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "boolean"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
let t = true;
|
||||
|
||||
let f: bool = false; // with explicit type annotation
|
||||
}
|
6
english/listings/ch03-common-programming-concepts/no-listing-09-char/Cargo.lock
generated
Normal file
6
english/listings/ch03-common-programming-concepts/no-listing-09-char/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "char"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "char"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
let c = 'z';
|
||||
let z = 'ℤ';
|
||||
let heart_eyed_cat = '😻';
|
||||
}
|
6
english/listings/ch03-common-programming-concepts/no-listing-10-tuples/Cargo.lock
generated
Normal file
6
english/listings/ch03-common-programming-concepts/no-listing-10-tuples/Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "tuples"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "tuples"
|
||||
version = "0.1.0"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user