diff options
| author | Jesse Jones <jesse9jones@gmail.com> | 2012-11-18 17:05:24 -0800 |
|---|---|---|
| committer | Jesse Jones <jesse9jones@gmail.com> | 2012-11-18 17:05:24 -0800 |
| commit | a24da7e254110dcd38183e73fa1bb9ef143a6b27 (patch) | |
| tree | 318b031d5d0345986b5c8234de7b9c8014716e82 /doc | |
| parent | e5c9a8a4796d668d20cae1b65e70dd6c2114562a (diff) | |
Discuss the types that may be used with const items.
Also removed vector example that doesn't compile. IMO closes #3341.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/rust.md | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/doc/rust.md b/doc/rust.md index bf28f2523af..3ca414006ce 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -1104,6 +1104,17 @@ Constants are declared with the `const` keyword. A constant item must have an expression giving its definition. The definition expression of a constant is limited to expression forms that can be evaluated at compile time. +Constants must be explicitly typed. The type may be ```bool```, ```char```, a number, or a type derived from +those primitive types. The derived types are borrowed pointers, static arrays, tuples, and structs. + +~~~~ +const bit1: uint = 1 << 0; +const bit2: uint = 1 << 1; + +const bits: [uint * 2] = [bit1, bit2]; +const bits_r: &[uint] = &bits; +~~~~ + ### Traits A _trait_ describes a set of method types. @@ -1562,7 +1573,6 @@ indicate that the elements of the resulting vector may be mutated. When no mutability is specified, the vector is immutable. ~~~~ -[] [1, 2, 3, 4]; ["a", "b", "c", "d"]; [0, ..128]; // vector with 128 zeros |
