Skip to content

Doc fixes for 0.6 incoming #5553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,10 @@ vec_elems : [expr [',' expr]*] | [expr ',' ".." expr]
A [_vector_](#vector-types) _expression_ is written by enclosing zero or
more comma-separated expressions of uniform type in square brackets.

In the `[expr ',' ".." expr]` form, the expression after the `".."`
must be a constant expression that can be evaluated at compile time, such
as a [literal](#literals) or a [static item](#static-items).

~~~~
[1, 2, 3, 4];
["a", "b", "c", "d"];
Expand Down Expand Up @@ -2156,6 +2160,19 @@ do f |j| {
}
~~~~

In this example, both calls to the (binary) function `k` are equivalent:

~~~~
# fn k(x:int, f: &fn(int)) { }
# fn l(i: int) { }

k(3, |j| l(j));

do k(3) |j| {
l(j);
}
~~~~


### For expressions

Expand Down Expand Up @@ -2184,7 +2201,7 @@ and early boolean-valued returns from the `block` function,
such that the meaning of `break` and `loop` is preserved in a primitive loop
when rewritten as a `for` loop controlled by a higher order function.

An example a for loop:
An example of a for loop over the contents of a vector:

~~~~
# type foo = int;
Expand All @@ -2198,6 +2215,14 @@ for v.each |e| {
}
~~~~

An example of a for loop over a series of integers:

~~~~
# fn bar(b:uint) { }
for uint::range(0, 256) |i| {
bar(i);
}
~~~~

### If expressions

Expand Down Expand Up @@ -2474,6 +2499,7 @@ fail_unless!(b != "world");

The vector type constructor represents a homogeneous array of values of a given type.
A vector has a fixed size.
(Operations like `vec::push` operate solely on owned vectors.)
A vector type can be annotated with a _definite_ size,
written with a trailing asterisk and integer literal, such as `[int * 10]`.
Such a definite-sized vector type is a first-class type, since its size is known statically.
Expand All @@ -2484,6 +2510,10 @@ such as `&[T]`, `@[T]` or `~[T]`.
The kind of a vector type depends on the kind of its element type,
as with other simple structural types.

Expressions producing vectors of definite size cannot be evaluated in a
context expecting a vector of indefinite size; one must copy the
definite-sized vector contents into a distinct vector of indefinite size.

An example of a vector type and its use:

~~~~
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ pub fn build_sized_opt<A,B: Buildable<A>>(size: Option<uint>,

// Functions that combine iteration and building

/// Applies a function to each element of an iterable and returns the results.
/// Applies a function to each element of an iterable and returns the results
/// in a sequence built via `BU`. See also `map_to_vec`.
#[inline(always)]
pub fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: &fn(&T) -> U)
-> BU {
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ pub fn with_capacity<T>(capacity: uint) -> ~[T] {
/**
* Builds a vector by calling a provided function with an argument
* function that pushes an element to the back of a vector.
* This version takes an initial size for the vector.
* This version takes an initial capacity for the vector.
*
* # Arguments
*
* * size - An initial size of the vector to reserve
* * builder - A function that will construct the vector. It recieves
* * builder - A function that will construct the vector. It receives
* as an argument a function that will push an element
* onto the vector being constructed.
*/
Expand All @@ -194,7 +194,7 @@ pub fn build_sized<A>(size: uint, builder: &fn(push: &fn(v: A))) -> ~[A] {
*
* # Arguments
*
* * builder - A function that will construct the vector. It recieves
* * builder - A function that will construct the vector. It receives
* as an argument a function that will push an element
* onto the vector being constructed.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ lib/ - bindings to LLVM
The files concerned purely with syntax -- that is, the AST, parser,
pretty-printer, lexer, macro expander, and utilities for traversing
ASTs -- are in a separate crate called "syntax", whose files are in
./../libsyntax if the parent directory of front/, middle/, back/, and
so on is . .
./../libsyntax, where . is the current directory (that is, the parent
directory of front/, middle/, back/, and so on).

The entry-point for the compiler is main() in driver/rustc.rs, and
this file sequences the various parts together.
Expand Down