Skip to content

Commit aa36593

Browse files
committed
---
yaml --- r: 153010 b: refs/heads/try2 c: bd893d1 h: refs/heads/master v: v3
1 parent b16e732 commit aa36593

File tree

489 files changed

+7811
-6581
lines changed

Some content is hidden

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

489 files changed

+7811
-6581
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: e11503f6d2b1766a852183f5591874ec53f6eae5
8+
refs/heads/try2: bd893d19223ae6979c180291be6b2a3b9311148a
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ documentation.
5454
When complete, `make install` will place several programs into
5555
`/usr/local/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
5656
API-documentation tool.
57-
system.
5857
3. Read the [tutorial].
5958
4. Enjoy!
6059

branches/try2/man/rustdoc.1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ directory to load plugins from (default: /tmp/rustdoc_ng/plugins)
3838
-L --library-path <val>
3939
directory to add to crate search path
4040
.TP
41+
--html-in-header <val>
42+
file to add to <head>
43+
.TP
44+
--html-before-content <val>
45+
file to add in <body>, before content
46+
.TP
47+
--html-after-content <val>
48+
file to add in <body>, after content
49+
.TP
4150
-h, --help
4251
Print help
4352

branches/try2/mk/dist.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ PKG_FILES := \
5454
driver \
5555
etc \
5656
$(foreach crate,$(CRATES),lib$(crate)) \
57+
libcoretest \
5758
libbacktrace \
5859
rt \
5960
rustllvm \

branches/try2/mk/docs.mk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ DOCS := index intro tutorial guide guide-ffi guide-macros guide-lifetimes \
3535
PDF_DOCS := tutorial rust
3636

3737
RUSTDOC_DEPS_rust := doc/full-toc.inc
38-
RUSTDOC_FLAGS_rust := --markdown-in-header=doc/full-toc.inc
38+
RUSTDOC_FLAGS_rust := --html-in-header=doc/full-toc.inc
3939

4040
L10N_LANGS := ja
4141

4242
# Generally no need to edit below here.
4343

4444
# The options are passed to the documentation generators.
45-
RUSTDOC_HTML_OPTS_NO_CSS = --markdown-before-content=doc/version_info.html \
46-
--markdown-in-header=doc/favicon.inc \
47-
--markdown-after-content=doc/footer.inc \
45+
RUSTDOC_HTML_OPTS_NO_CSS = --html-before-content=doc/version_info.html \
46+
--html-in-header=doc/favicon.inc \
47+
--html-after-content=doc/footer.inc \
4848
--markdown-playground-url='http://play.rust-lang.org/'
4949

5050
RUSTDOC_HTML_OPTS = $(RUSTDOC_HTML_OPTS_NO_CSS) --markdown-css rust.css

branches/try2/mk/tests.mk

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
######################################################################
1515

1616
# The names of crates that must be tested
17-
TEST_TARGET_CRATES = $(TARGET_CRATES)
17+
18+
# libcore tests are in a separate crate
19+
DEPS_coretest :=
20+
$(eval $(call RUST_CRATE,coretest))
21+
22+
TEST_TARGET_CRATES = $(filter-out core,$(TARGET_CRATES)) coretest
1823
TEST_DOC_CRATES = $(DOC_CRATES)
1924
TEST_HOST_CRATES = $(HOST_CRATES)
2025
TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
@@ -172,7 +177,7 @@ check-notidy: cleantmptestlogs cleantestlibs all check-stage2
172177
$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
173178

174179
check-lite: cleantestlibs cleantmptestlogs \
175-
$(foreach crate,$(TARGET_CRATES),check-stage2-$(crate)) \
180+
$(foreach crate,$(TEST_TARGET_CRATES),check-stage2-$(crate)) \
176181
check-stage2-rpass \
177182
check-stage2-rfail check-stage2-cfail check-stage2-rmake
178183
$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

branches/try2/src/doc/guide-unsafe.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,12 @@ impl<T: Send> Drop for Unique<T> {
267267
// A comparison between the built-in `Box` and this reimplementation
268268
fn main() {
269269
{
270-
let mut x = box 5;
270+
let mut x = box 5i;
271271
*x = 10;
272272
} // `x` is freed here
273273
274274
{
275-
let mut y = Unique::new(5);
275+
let mut y = Unique::new(5i);
276276
*y.borrow_mut() = 10;
277277
} // `y` is freed here
278278
}
@@ -678,7 +678,7 @@ unsafe fn deallocate(ptr: *mut u8, _size: uint, _align: uint) {
678678
679679
#[start]
680680
fn main(argc: int, argv: *const *const u8) -> int {
681-
let x = box 1;
681+
let x = box 1i;
682682
683683
0
684684
}

branches/try2/src/doc/guide.md

Lines changed: 226 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Save the file, and then type this into your terminal window:
160160

161161
```{bash}
162162
$ rustc hello_world.rs
163-
$ ./hello_world # just 'hello_world' on Windows
163+
$ ./hello_world # or hello_world.exe on Windows
164164
Hello, world
165165
```
166166

@@ -243,7 +243,7 @@ There are now two files: our source code, with the `.rs` extension, and the
243243
executable (`hello_world.exe` on Windows, `hello_world` everywhere else)
244244

245245
```{bash}
246-
$ ./hello_world # or ./hello_world.exe on Windows
246+
$ ./hello_world # or hello_world.exe on Windows
247247
```
248248

249249
This prints out our `Hello, world!` text to our terminal.
@@ -285,8 +285,9 @@ At first, your program doesn't have any dependencies, so we'll only be using
285285
the first part of its functionality. Eventually, we'll add more. Since we
286286
started off by using Cargo, it'll be easy to add later.
287287

288-
Let's convert Hello World to Cargo. The first thing we need to do is install
289-
it. To do this, we need to build it from source. There are no binaries yet.
288+
Let's convert Hello World to Cargo. The first thing we need to do to begin using Cargo
289+
is to install Cargo. To do this, we need to build it from source. There are no binaries
290+
yet.
290291

291292
First, let's go back to our projects directory. We don't want Cargo to
292293
live in our project!
@@ -412,23 +413,209 @@ rest of your Rust career.
412413
Next, we'll learn more about Rust itself, by starting to write a more complicated
413414
program. We hope you want to do more with Rust than just print "Hello, world!"
414415

415-
## If
416+
## Guessing Game
416417

417-
## Functions
418+
Let's write a bigger program in Rust. We could just go through a laundry list
419+
of Rust features, but that's boring. Instead, we'll learn more about how to
420+
code in Rust by writing a few example projects.
418421

419-
return
422+
For our first project, we'll implement a classic beginner programming problem:
423+
the guessing game. Here's how it works: Our program will generate a random
424+
integer between one and a hundred. It will then prompt us to enter a guess.
425+
Upon entering our guess, it will tell us if we're too low or too high. Once we
426+
guess correctly, it will congratulate us, and print the number of guesses we've
427+
taken to the screen. Sound good? It sounds easy, but it'll end up showing off a
428+
number of basic features of Rust.
420429

421-
comments
430+
### Set up
422431

423-
## Testing
432+
Let's set up a new project. Go to your projects directory, and make a new
433+
directory for the project, as well as a `src` directory for our code:
424434

425-
attributes
435+
```{bash}
436+
$ cd ~/projects
437+
$ mkdir guessing_game
438+
$ cd guessing_game
439+
$ mkdir src
440+
```
426441

427-
stability markers
442+
Great. Next, let's make a `Cargo.toml` file so Cargo knows how to build our
443+
project:
428444

429-
## Crates and Modules
445+
```{ignore}
446+
[package]
430447
431-
visibility
448+
name = "guessing_game"
449+
version = "0.1.0"
450+
authors = [ "[email protected]" ]
451+
452+
[[bin]]
453+
454+
name = "guessing_game"
455+
```
456+
457+
Finally, we need our source file. Let's just make it hello world for now, so we
458+
can check that our setup works. In `src/guessing_game.rs`:
459+
460+
```{rust}
461+
fn main() {
462+
println!("Hello world!");
463+
}
464+
```
465+
466+
Let's make sure that worked:
467+
468+
```{bash}
469+
$ cargo build
470+
Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
471+
$
472+
```
473+
474+
Excellent! Open up your `src/guessing_game.rs` again. We'll be writing all of
475+
our code in this file. The next section of the tutorial will show you how to
476+
build multiple-file projects.
477+
478+
## Variable bindings
479+
480+
The first thing we'll learn about are 'variable bindings.' They look like this:
481+
482+
```{rust}
483+
let x = 5i;
484+
```
485+
486+
In many languages, this is called a 'variable.' But Rust's variable bindings
487+
have a few tricks up their sleeves. Rust has a very powerful feature called
488+
'pattern matching' that we'll get into detail with later, but the left
489+
hand side of a `let` expression is a full pattern, not just a variable name.
490+
This means we can do things like:
491+
492+
```{rust}
493+
let (x, y) = (1i, 2i);
494+
```
495+
496+
After this expression is evaluated, `x` will be one, and `y` will be two.
497+
Patterns are really powerful, but this is about all we can do with them so far.
498+
So let's just keep this in the back of our minds as we go forward.
499+
500+
By the way, in these examples, `i` indicates that the number is an integer.
501+
502+
Rust is a statically typed language, which means that we specify our types up
503+
front. So why does our first example compile? Well, Rust has this thing called
504+
"[Hindley-Milner type
505+
inference](http://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_system)",
506+
named after some really smart type theorists. If you clicked that link, don't
507+
be scared: what this means for you is that Rust will attempt to infer the types
508+
in your program, and it's pretty good at it. If it can infer the type, Rust
509+
doesn't require you to actually type it out.
510+
511+
We can add the type if we want to. Types come after a colon (`:`):
512+
513+
```{rust}
514+
let x: int = 5;
515+
```
516+
517+
If I asked you to read this out loud to the rest of the class, you'd say "`x`
518+
is a binding with the type `int` and the value `five`." Rust requires you to
519+
initialize the binding with a value before you're allowed to use it. If
520+
we try...
521+
522+
```{ignore}
523+
let x;
524+
```
525+
526+
...we'll get an error:
527+
528+
```{ignore}
529+
src/guessing_game.rs:2:9: 2:10 error: cannot determine a type for this local variable: unconstrained type
530+
src/guessing_game.rs:2 let x;
531+
^
532+
```
533+
534+
Giving it a type will compile, though:
535+
536+
```{ignore}
537+
let x: int;
538+
```
539+
540+
Let's try it out. Change your `src/guessing_game.rs` file to look like this:
541+
542+
```{rust}
543+
fn main() {
544+
let x: int;
545+
546+
println!("Hello world!");
547+
}
548+
```
549+
550+
You can use `cargo build` on the command line to build it. You'll get a warning,
551+
but it will still print "Hello, world!":
552+
553+
```{ignore,notrust}
554+
Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
555+
src/guessing_game.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default
556+
src/guessing_game.rs:2 let x: int;
557+
^
558+
```
559+
560+
Rust warns us that we never use the variable binding, but since we never use it,
561+
no harm, no foul. Things change if we try to actually use this `x`, however. Let's
562+
do that. Change your program to look like this:
563+
564+
```{rust,ignore}
565+
fn main() {
566+
let x: int;
567+
568+
println!("The value of x is: {}", x);
569+
}
570+
```
571+
572+
And try to build it. You'll get an error:
573+
574+
```{bash}
575+
$ cargo build
576+
Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
577+
src/guessing_game.rs:4:39: 4:40 error: use of possibly uninitialized variable: `x`
578+
src/guessing_game.rs:4 println!("The value of x is: {}", x);
579+
^
580+
note: in expansion of format_args!
581+
<std macros>:2:23: 2:77 note: expansion site
582+
<std macros>:1:1: 3:2 note: in expansion of println!
583+
src/guessing_game.rs:4:5: 4:42 note: expansion site
584+
error: aborting due to previous error
585+
Could not execute process `rustc src/guessing_game.rs --crate-type bin --out-dir /home/you/projects/guessing_game/target -L /home/you/projects/guessing_game/target -L /home/you/projects/guessing_game/target/deps` (status=101)
586+
```
587+
588+
Rust will not let us use a value that has not been initialized. So why let us
589+
declare a binding without initializing it? You'd think our first example would
590+
have errored. Well, Rust is smarter than that. Before we get to that, let's talk
591+
about this stuff we've added to `println!`.
592+
593+
If you include two curly braces (`{}`, some call them moustaches...) in your
594+
string to print, Rust will interpret this as a request to interpolate some sort
595+
of value. **String interpolation** is a computer science term that means "stick
596+
in the middle of a string." We add a comma, and then `x`, to indicate that we
597+
want `x` to be the value we're interpolating. The comma is used to separate
598+
arguments we pass to functions and macros, if you're passing more than one.
599+
600+
When you just use the double curly braces, Rust will attempt to display the
601+
value in a meaningful way by checking out its type. If you want to specify the
602+
format in a more detailed manner, there are a [wide number of options
603+
available](/std/fmt/index.html). Fow now, we'll just stick to the default:
604+
integers aren't very complicated to print.
605+
606+
So, we've cleared up all of the confusion around bindings, with one exception:
607+
why does Rust let us declare a variable binding without an initial value if we
608+
must initialize the binding before we use it? And how does it know that we have
609+
or have not initialized the binding? For that, we need to learn our next
610+
concept: `if`.
611+
612+
## If
613+
614+
## Functions
615+
616+
return
617+
618+
comments
432619

433620
## Compound Data Types
434621

@@ -450,10 +637,35 @@ loop
450637

451638
break/continue
452639

453-
iterators
640+
## Guessing Game: complete
641+
642+
At this point, you have successfully built the Guessing Game! Congratulations!
643+
For reference, [We've placed the sample code on
644+
GitHub](https://github.com/steveklabnik/guessing_game).
645+
646+
You've now learned the basic syntax of Rust. All of this is relatively close to
647+
various other programming languages you have used in the past. These
648+
fundamental syntactical and semantic elements will form the foundation for the
649+
rest of your Rust education.
650+
651+
Now that you're an expert at the basics, it's time to learn about some of
652+
Rust's more unique features.
653+
654+
## iterators
454655

455656
## Lambdas
456657

658+
## Testing
659+
660+
attributes
661+
662+
stability markers
663+
664+
## Crates and Modules
665+
666+
visibility
667+
668+
457669
## Generics
458670

459671
## Traits

0 commit comments

Comments
 (0)