Revert "docs: Call () 'unit' instead of 'nil'"
This reverts commit c8ee49a5b6
.
This commit is contained in:
parent
83fdeddb91
commit
3e47b4f17e
|
@ -246,7 +246,7 @@ define a struct type with the same contents, and declare
|
||||||
`gettimeofday` to take a pointer to such a struct.
|
`gettimeofday` to take a pointer to such a struct.
|
||||||
|
|
||||||
The second argument to `gettimeofday` (the time zone) is not used by
|
The second argument to `gettimeofday` (the time zone) is not used by
|
||||||
this program, so it simply declares it to be a pointer to the unit
|
this program, so it simply declares it to be a pointer to the nil
|
||||||
type. Since all null pointers have the same representation regardless of
|
type. Since all null pointers have the same representation regardless of
|
||||||
their referent type, this is safe.
|
their referent type, this is safe.
|
||||||
|
|
||||||
|
|
|
@ -294,11 +294,11 @@ are not semicolons in the blocks of the second snippet. This is
|
||||||
important; the lack of a semicolon after the last statement in a
|
important; the lack of a semicolon after the last statement in a
|
||||||
braced block gives the whole block the value of that last expression.
|
braced block gives the whole block the value of that last expression.
|
||||||
|
|
||||||
Put another way, the semicolon in Rust *ignores the value of an
|
Put another way, the semicolon in Rust *ignores the value of an expression*.
|
||||||
expression*. Thus, if the branches of the `if` had looked like `{ 4; }`,
|
Thus, if the branches of the `if` had looked like `{ 4; }`, the above example
|
||||||
the above example would simply assign `()` (unit or void) to
|
would simply assign `()` (nil or void) to `price`. But without the semicolon, each
|
||||||
`price`. But without the semicolon, each branch has a different value,
|
branch has a different value, and `price` gets the value of the branch that
|
||||||
and `price` gets the value of the branch that was taken.
|
was taken.
|
||||||
|
|
||||||
In short, everything that's not a declaration (`let` for variables,
|
In short, everything that's not a declaration (`let` for variables,
|
||||||
`fn` for functions, et cetera) is an expression, including function bodies.
|
`fn` for functions, et cetera) is an expression, including function bodies.
|
||||||
|
@ -839,7 +839,7 @@ fn point_from_direction(dir: Direction) -> Point {
|
||||||
Tuples in Rust behave exactly like structs, except that their fields
|
Tuples in Rust behave exactly like structs, except that their fields
|
||||||
do not have names (and can thus not be accessed with dot notation).
|
do not have names (and can thus not be accessed with dot notation).
|
||||||
Tuples can have any arity except for 0 or 1 (though you may consider
|
Tuples can have any arity except for 0 or 1 (though you may consider
|
||||||
unit, `()`, as the empty tuple if you like).
|
nil, `()`, as the empty tuple if you like).
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
let mytup: (int, int, float) = (10, 20, 30.0);
|
let mytup: (int, int, float) = (10, 20, 30.0);
|
||||||
|
@ -891,7 +891,7 @@ fn int_to_str(i: int) -> ~str {
|
||||||
}
|
}
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
Functions that do not return a value are said to return unit, `()`,
|
Functions that do not return a value are said to return nil, `()`,
|
||||||
and both the return type and the return value may be omitted from
|
and both the return type and the return value may be omitted from
|
||||||
the definition. The following two functions are equivalent.
|
the definition. The following two functions are equivalent.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue