You build it with `cd doc/tutorial; node build.js`, and then point your browser at doc/tutorial/web/index.html. Not remotely ready for publicity yet.
1.7 KiB
Introduction
Scope
This is a tutorial for the Rust programming language. It assumes the reader is familiar with the basic concepts of programming, and has programmed in one or more other languages before. The tutorial covers the whole language, though not with the depth and precision of the language reference.
FIXME: maybe also the stdlib?
Disclaimer
Rust is a language under development. The general flavor of the language has settled, but details will continue to change as it is further refined. Nothing in this tutorial is final, and though we try to keep it updated, it is possible that the text occasionally does not reflect the actual state of the language.
First Impressions
Though syntax is something you get used to, an initial encounter with a language can be made easier if the notation looks familiar. Rust is a curly-brace language in the tradition of C, C++, and JavaScript.
fn fac(n: int) -> int {
let result = 1;
while n > 0 {
result *= n;
n -= 1;
}
ret result;
}
Several differences from C stand out. Types do not come before, but
after variable names (preceded by a colon). In local variables
(introduced with let
), they are optional, and will be inferred when
left off. Constructs like while
and if
do not require parenthesis
around the condition (though they allow them). Also, there's a
tendency towards aggressive abbreviation in the keywords—fn
for
function, ret
for return.
You should, however, not conclude that Rust is simply an evolution of C. As will become clear in the rest of this tutorial, it goes into quite a different direction.