Skip to content

Commit

Permalink
Merge pull request rust-lang#306 from GBGamer/link-ref-correct
Browse files Browse the repository at this point in the history
Changed [link](example.com) to [link][example]
  • Loading branch information
steveklabnik committed Dec 11, 2014
2 parents 7d5774c + 107e91e commit 7173c8d
Show file tree
Hide file tree
Showing 30 changed files with 170 additions and 71 deletions.
10 changes: 7 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## I would like to see an example about $TOPIC

Please check if such topic is already part of our
[TODO list](/~https://github.com/rust-lang/rust-by-example/issues/1). If that's
[TODO list][issues-all]. If that's
not the case, leave your request as a comment on that issue.

## There's a typo/error in example $X
Expand All @@ -27,7 +27,7 @@ start the commit message with the example id, e.g. "type/literals: fix typo".
## Check if there is an action plan for that topic

Look for
[issues](/~https://github.com/rust-lang/rust-by-example/issues?labels=&page=1&state=open)
[issues][issues-open]
that have a C-* label:

* C-new: A new chapter, there probably a lot to do here.
Expand All @@ -48,7 +48,7 @@ plan to work on.

## Hack away

See the [README](README.md) for details about how the static site is generated.
See the [README][readme] for details about how the static site is generated.

## Finally, send a PR

Expand Down Expand Up @@ -83,3 +83,7 @@ Use:
* Lines should contain a maximum of 79 characters.
* In comments, types, methods, macros and variables should be wrapped in
backticks, e.g. ``` `println!` ```

[issues-all]: /~https://github.com/rust-lang/rust-by-example/issues/
[issues-open]: /~https://github.com/rust-lang/rust-by-example/issues?labels=&page=1&state=open
[readme]: README.md
37 changes: 25 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[![Build Status](https://travis-ci.org/rust-lang/rust-by-example.svg?branch=master)](https://travis-ci.org/rust-lang/rust-by-example)
[![Build Status][travis-image]][travis-link]
# Rust by Example

## What's this?

This is the source code of the
[Rust by example](http://rustbyexample.com) website!
[Rust by example][website] website!

## How to contribute

See [CONTRIBUTING.md](CONTRIBUTING.md).
See [CONTRIBUTING.md][how-to-contribute].

## How to generate the static site

Expand All @@ -19,42 +19,42 @@ make book GITBOOK=`pwd`/node_modules/.bin/gitbook
make test GITBOOK=`pwd`/node_modules/.bin/gitbook
```

View the results with `make serve GITBOOK=`pwd`/node_modules/.bin/gitbook`.
View the results with ```make serve GITBOOK=`pwd`/node_modules/.bin/gitbook```.

Note: on Ubuntu `node` may be called `nodejs`. I had to edit `.bin/gitbook` accordingly.

### Details

We use these tools to generate the static site:

* [Rust](http://www.rust-lang.org/) \o/
* [gitbook](http://www.gitbook.io)
* [Rust][rust-lang] \o/
* [gitbook][gitbook]

`gitbook` will generate the site from markdown files (see details about how it
works [here](/~https://github.com/GitbookIO/gitbook#book-format)).
works [here][gitbook-format]).

Before running `gitbook`, we do a preprocessing step using
[src/update.rs](src/update.rs).
[src/update.rs][update-rs].

This preprocessing has two steps:

### Generating the `SUMMARY.md`

`SUMMARY.md` is generated from the
[examples/structure.json](examples/structure.json) file. This JSON file
[examples/structure.json][structure] file. This JSON file
contains a tree-like structure of "examples".

Each example has:

* an id, e.g. `hello`
* a title, e.g. `Hello World`
* optionally, children, which is a vector of sub-examples, e.g. `null`
* a directory under `examples`, e.g. [examples/hello](examples/hello)
* a directory under `examples`, e.g. [examples/hello][hello-folder]
* an entry in examples/structure.json, e.g.
`{ "id": "hello", "title": "Hello World", "children": null }`
* some source file(s), e.g. [examples/hello/hello.rs](examples/hello/hello.rs)
* some source file(s), e.g. [examples/hello/hello.rs][hello-rs]
* an input markdown file, e.g.
[examples/hello/input.md](examples/hello/input.md)
[examples/hello/input.md][hello-md]

When dealing with a child example, the path will have to include the id of its
ancestors; e.g. `examples/variable/mut/input.md`, implies that a `mut` example
Expand Down Expand Up @@ -87,3 +87,16 @@ Rust by example is dual licensed under the Apache 2.0 license and the MIT
license.

See LICENSE-APACHE and LICENSE-MIT for more details.

[travis-image]: https://travis-ci.org/rust-lang/rust-by-example.svg?branch=master
[travis-link]: https://travis-ci.org/rust-lang/rust-by-example
[website]: http://rustbyexample.com
[how-to-contribute]: CONTRIBUTING.md
[rust-lang]: http://www.rust-lang.org/
[gitbook]: http://www.gitbook.io
[gitbook-dir]: /~https://github.com/GitbookIO/gitbook#book-format
[update-rs]: src/update.rs
[structure]: examples/structure.json
[hello-folder]: examples/hello
[hello-rs]: examples/hello/hello.rs
[hello-md]: examples/hello/input.md
10 changes: 7 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Rust by Example

[Rust](http://www.rust-lang.org/) is a programming language with a focus on
[Rust][rust] is a programming language with a focus on
type safety, memory safety, concurrency and performance.

This book is a collection of bitesize examples that illustrate various rustic
concepts and the Rust distribution libraries.

Be sure to have rust [installed](http://www.rust-lang.org/install.html) and the
[docs](http://doc.rust-lang.org/std/) at hand, let's
Be sure to have rust [installed][install] and the
[docs][std] at hand, let's
start!

*Note*: This book will follow the nightly version of Rust until we reach
version 1.0, it's highly possible that some examples won't work with snapshot
version like 0.10, be sure to use a nightly version!

[rust]: http://www.rust-lang.org/
[install]: http://www.rust-lang.org/install.html
[std]: http://doc.rust-lang.org/std/
10 changes: 7 additions & 3 deletions examples/attribute/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ An attribute is metadata applied to some module, crate or item. This metadata
can be used to/for:

<!-- TODO: Link these to their respective examples -->
* [conditional compilation of code](/attribute/cfg.html)
* [set crate name, version and type (binary or library)](/attribute/crate.html)
* disable [lints](https://en.wikipedia.org/wiki/Lint_%28software%29) (warnings)
* [conditional compilation of code][cfg]
* [set crate name, version and type (binary or library)][config]
* disable [lints][lint] (warnings)
* enable compiler features (macros, glob imports, etc.)
* link to a foreign library
* mark functions as unit tests
Expand All @@ -19,3 +19,7 @@ Attributes can take arguments with different syntaxes:
* `#[attribute = "value"]`
* `#[attribute(key = "value")]`
* `#[attribute(value)]`

[cfg]: /attribute/cfg.html
[crate]: /attribute/crate.html
[lint]: https://en.wikipedia.org/wiki/Lint_%28software%29
4 changes: 3 additions & 1 deletion examples/crates/lib/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ liberty.rlib

Libraries get prefixed with "lib", and by default they get named after their
crate file, but this default name can be overridden using the
[`crate_name` attribute](/attribute/crate.html).
[`crate_name` attribute][crate-name].

[crate-name]: /attribute/crate.html
7 changes: 5 additions & 2 deletions examples/enum/input.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
The `enum` keyword allows the creation of
[tagged unions](http://en.wikipedia.org/wiki/Tagged_union), which can be used
[tagged unions][tag-union], which can be used
as algebraic data types
([ADT](http://en.wikipedia.org/wiki/Algebraic_data_type)).
([ADT][adt]).

{enum.play}

[adt]: http://en.wikipedia.org/wiki/Algebraic_data_type
[tag-union]: http://en.wikipedia.org/wiki/Tagged_union
7 changes: 5 additions & 2 deletions examples/expression/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ returns a value. This may not always be desired, so the output can be
suppressed by ending the expression with a semicolon `;`.

Blocks are expressions too, so they can be used as
[r-values](https://en.wikipedia.org/wiki/Value_%28computer_science%29#lrvalue)
[r-values][rvalue]
in assignments. The last expression in the block will be assigned to the
[l-value](https://en.wikipedia.org/wiki/Value_%28computer_science%29#lrvalue).
[l-value][lvalue].
But, if the last expression of the block ends with a semicolon, the return
value will be `()`.

{expression.play}

[rvalue]: https://en.wikipedia.org/wiki/Value_%28computer_science%29#lrvalue
[lvalue]: https://en.wikipedia.org/wiki/Value_%28computer_science%29#lrvalue
4 changes: 3 additions & 1 deletion examples/file/create/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
failure conditions)

There is also a more generic
[`open_mode`](http://doc.rust-lang.org/std/io/fs/struct.File.html#method.open_mode)
[`open_mode`][open-mode]
method that can open files in other modes like: read+write, append, etc.

[open-mode]: http://doc.rust-lang.org/std/io/fs/struct.File.html#method.open_mode
4 changes: 3 additions & 1 deletion examples/fn/unused/input.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
The compiler provides a `dead_code`
[*lint*](https://en.wikipedia.org/wiki/Lint_%28software%29) that will warn
[*lint*][lint] that will warn
about unused functions. An *attribute* can be used to disable the lint.

{unused.play}

Note that in real programs, you should eliminate dead code. In these examples
we'll allow dead code in some places because of the interactive nature of the
examples.

[lint]: https://en.wikipedia.org/wiki/Lint_%28software%29
4 changes: 3 additions & 1 deletion examples/fs/input.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The [`std::io::fs`](http://doc.rust-lang.org/std/io/fs/)
The [`std::io::fs`][std-fs]
module contains several functions that deal with the filesystem.

{fs.play}
Expand Down Expand Up @@ -39,3 +39,5 @@ a
1 directory, 2 files
```

[std-fs]: http://doc.rust-lang.org/std/io/fs/
7 changes: 5 additions & 2 deletions examples/hof/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ give Rust its functional flavor.

{hof.play}

[Option](http://doc.rust-lang.org/core/option/type.Option.html)
[Option][option]
and
[Iterator](http://doc.rust-lang.org/core/iter/trait.Iterator.html)
[Iterator][iter]
implement their fair share of HOFs.

[option]: http://doc.rust-lang.org/core/option/type.Option.html
[iter]: http://doc.rust-lang.org/core/iter/trait.Iterator.html
4 changes: 3 additions & 1 deletion examples/iter/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ arrays) and lazy value generators.
{iter.play}

The `Iterator` trait gives access to
[several methods](http://doc.rust-lang.org/core/iter/trait.Iterator.html).
[several methods][iter].

[iter]: http://doc.rust-lang.org/core/iter/trait.Iterator.html
7 changes: 5 additions & 2 deletions examples/lifetime/borrow/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ The programmer doesn't need to explicitly annotate lifetimes (nor understand
what are lifetimes), for the borrow checker to do its job in most cases. These
are the cases where explicit lifetimes are required:

* [Functions that return references](/lifetime/fn.html)
* [Structs that hold references](/lifetime/struct.html)
* [Functions that return references][lifetime]
* [Structs that hold references][structs]

[lifetime]: /lifetime/fn.html
[structs]: /lifetime/struct.html
10 changes: 7 additions & 3 deletions examples/literals/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ Underscores can be inserted in numeric literals to improve readability, e.g.
We need to tell the compiler what is the type of the literals we use. For now,
we'll use the `u` suffix to indicate that the literal is an unsigned integer,
and the `i` suffix to indicate that it's a signed integer. We'll cover the type
system in [another chapter](/type.html), and give more details about type
annotating literals in [their own section](/type/literals.html).
system in [another chapter][type], and give more details about type
annotating literals in [their own section][type-literal].

The operators available and their precedence are similar to other
[C-like languages](https://en.wikipedia.org/wiki/Operator_precedence#Programming_languages).
[C-like languages][op-prec].

{literals.play}

[op-prec]: https://en.wikipedia.org/wiki/Operator_precedence#Programming_languages
[type]: /type.html
[type-literal]: /type/literals.html
4 changes: 3 additions & 1 deletion examples/mod/split/input.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Modules can be mapped to a file/directory hierarchy. Let's break down the
[visibility example](/mod/visibility.html) in files:
[visibility example][visibility] in files:

```
$ tree .
Expand Down Expand Up @@ -29,3 +29,5 @@ called `my::indirect_access()`, that
> called `my::private_function()`
called `my::nested::function()`
```

[visibility]: /mod/visibility.html
4 changes: 3 additions & 1 deletion examples/ops/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ any implementor of the `Add` trait will be able to use the `+` operator.

{operator.play}

Here is a [list](http://doc.rust-lang.org/core/ops/) of
Here is a [list][ops] of
the traits that overload operators.

[ops]: http://doc.rust-lang.org/core/ops/
10 changes: 7 additions & 3 deletions examples/path/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ instead is stored as a vector of bytes (`Vec<u8>`). Therefore, converting a
{path.play}

Be sure to check at other `Path` methods
([`posix::Path`](http://doc.rust-lang.org/std/path/posix/struct.Path.html)
or [`windows::Path`](http://doc.rust-lang.org/std/path/windows/struct.Path.html))
([`posix::Path`][posix-path]
or [`windows::Path`][windows-path])
and the
[`FileStat`](http://doc.rust-lang.org/std/io/struct.FileStat.html)
[`FileStat`][file-stat]
struct.

[posix-path]: http://doc.rust-lang.org/std/path/posix/struct.Path.html
[windows-path]: http://doc.rust-lang.org/std/path/windows/struct.Path.html
[file-stat]: http://doc.rust-lang.org/std/io/struct.FileStat.html
4 changes: 3 additions & 1 deletion examples/print/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ be checked at compile time.
{print.play}

For more information about formatting, take a look at
[std::fmt](http://doc.rust-lang.org/std/fmt/).
[std::fmt][fmt].

[fmt]: http://doc.rust-lang.org/std/fmt/
4 changes: 3 additions & 1 deletion examples/raii/input.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Variables in Rust do more than just hold data in the stack, they can also *own*
resources, e.g. `Box<T>` owns memory in the heap. Because Rust enforces the
[RAII](http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization)
[RAII][raii]
discipline, whenever an object goes out of scope, its destructor is called
and the resources *owned* by it are freed. This behavior shields against
*resource leak* bugs.
Expand Down Expand Up @@ -28,3 +28,5 @@ $ rustc raii.rs && valgrind ./raii
```

You'll never have to manually free memory again or worry about memory leaks!

[raii]: http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization
4 changes: 3 additions & 1 deletion examples/result/try/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ and the `Ok(ok)` branch expands to an `ok` expression.

{try.play}

Be sure to check the [documentation](http://doc.rust-lang.org/std/result/index.html),
Be sure to check the [documentation][docs],
as there are many methods to map/compose `Result`.

[docs]: http://doc.rust-lang.org/std/result/index.html
4 changes: 3 additions & 1 deletion examples/sockets/input.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Inter-Process Communication (IPC) for client-server applications can be
accomplished using
[UNIX sockets](http://en.wikipedia.org/wiki/Unix_domain_socket).
[UNIX sockets][unix-sockets].

Both client and server need to use the same path for the socket.

Expand Down Expand Up @@ -30,3 +30,5 @@ $ ./client hello
Server started, waiting for clients
Client said: hello
```

[unix-sockets]: http://en.wikipedia.org/wiki/Unix_domain_socket
3 changes: 2 additions & 1 deletion examples/staging/fmt/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ We've seen that formatting is specified via a *format string*:

* `format!("{}", foo)` -> `"3735928559"`
* `format!("0x{:X}", foo)` ->
[`"0xDEADBEEF"`](https://en.wikipedia.org/wiki/Deadbeef#Magic_debug_values)
[`"0xDEADBEEF"`][deadbeef]
* `format!("0o{:o}", foo)` -> `"0o33653337357"`

The same variable (`foo`) can be formatted differently depending on which
Expand Down Expand Up @@ -32,3 +32,4 @@ Here's the full list of formatting traits and their respective argument types:
* `E` -> `UpperExp`
* `?` -> `Poly`

[deadbeef]: https://en.wikipedia.org/wiki/Deadbeef#Magic_debug_values
7 changes: 5 additions & 2 deletions examples/str/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ can be used to view into a `String`, just like `&[T]` is a view into `Vec<T>`.
{str.play}

More `str`/`String` methods can be found under the
[std::str](http://doc.rust-lang.org/std/str/) and
[std::string](http://doc.rust-lang.org/std/string/)
[std::str][str] and
[std::string][string]
modules

[str]: http://doc.rust-lang.org/std/str/
[string]: http://doc.rust-lang.org/std/string/
Loading

0 comments on commit 7173c8d

Please sign in to comment.