]> git.lizzy.rs Git - rust.git/blob - src/libstd/unit.rs
rollup merge of #21678: vojtechkral/threads-native-names
[rust.git] / src / libstd / unit.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![doc(primitive = "unit")]
12 #![stable(feature = "rust1", since = "1.0.0")]
13
14 //! The `()` type, sometimes called "unit" or "nil".
15 //!
16 //! The `()` type has exactly one value `()`, and is used when there
17 //! is no other meaningful value that could be returned. `()` is most
18 //! commonly seen implicitly: functions without a `-> ...` implicitly
19 //! have return type `()`, that is, these are equivalent:
20 //!
21 //! ```rust
22 //! fn long() -> () {}
23 //!
24 //! fn short() {}
25 //! ```
26 //!
27 //! The semicolon `;` can be used to discard the result of an
28 //! expression at the end of a block, making the expression (and thus
29 //! the block) evaluate to `()`. For example,
30 //!
31 //! ```rust
32 //! fn returns_i64() -> i64 {
33 //!     1i64
34 //! }
35 //! fn returns_unit() {
36 //!     1i64;
37 //! }
38 //!
39 //! let is_i64 = {
40 //!     returns_i64()
41 //! };
42 //! let is_unit = {
43 //!     returns_i64();
44 //! };
45 //! ```