rust-by-example 0,3,0,0,2,0,5,1

Learn Rust with examples (Live code editor included)

Rust by Example

Build Status

What’s this?

This is the source code of the Rust by Example website!

How to contribute


How to generate the static site

Debian (Ubuntu) prerequisites

Install Rust and run:

sudo apt-get install nodejs npm subversion calibre
sudo ln -s /usr/bin/nodejs /usr/bin/node

Non-Debian prerequisites

Install Rust nightly, node, npm, subversion and calibre.

Build instructions


make all
make html pdf epub
make test

View the results with make serve.


We use these tools to generate the static site:

gitbook will generate the site from Markdown files (see details about how it works here).

Before running gitbook, we do a preprocessing step using src/

This preprocessing has two steps:

Generating the is generated from the examples/structure.json 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
  • an entry in examples/structure.json, e.g. { "id": "hello", "title": "Hello World", "children": null }
  • some source file(s), e.g. examples/hello/
  • an input markdown file, e.g. examples/hello/

When dealing with a child example, the path will have to include the id of its ancestors; e.g. examples/variable/mut/, implies that a mut example lives under the variable example.


Instead of including the Rust code directly in, the code lives in separate source files; the preprocessing step will insert the source code into the Markdown file.

For example, to insert the source code of the file, the following syntax is used in the Markdown file:

  • {} expands the source code embedded in a live code editor
  • {} expands to static/plain source code.
  • {hello.out} expands to the output of executing the source code.

The Makefile provides the following recipes:

  • make: builds and does the preprocessing step
  • make book: runs gitbook to generate the book
  • make serve: runs gitbook --serve to generate the book and publishes it under localhost:4000
  • make test: will check all the rust source files for compilation errors

Translations to other languages


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.

Related Repositories



Learn Rust with examples (Live code editor included) ...



通过例子学习Rust语言 ...



Перевод книги ...



Изучаем язык программирования Rust на примерах ...



Simple examples on how to wire in rust code built by cargo in an autotools-based project ...

Top Contributors

steveklabnik mdinger Xmasreturns ubsan brson spastorino japaric klampworks dbbrian lovasoa vbuslov justanotheranonymoususer letheed emkay iKevinY arvidj aakloxu jacob-hegna tpasternak vojtechkral stevegury robinst chriskrycho JackDanger badboy maxd nodakai naveensrinivasan battisti joemphilips