On 2/26/13 5:25 PM, Nathan Fiedler wrote:
Hello all

I was reading the language tutorial and had a couple of questions. I
hope this is the appropriate forum for asking them.

In section 4.1 the example has "return 0", seemingly as an expression.
Is that correct usage? Should it not simply be "0" instead?

`return 0` is an expression in Rust. The typechecker considers the type of a `return` expression compatible with every other type. This is because the form causes the function to immediately exit, so the "result" of `return` is meaningless.

Section 5.3 describes tuples and the ways in which you _cannot_ access
the fields (i.e. not by name or dot notation). So I'm left wondering how
one accesses the fields of a tuple. Must it always be through pattern
matching?

In the core language you have to use pattern matching. But there are methods in `core::tuple` that provide `.first()` and `.second()` convenience methods.

Patrick

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to