Skip to content

Commit 9f23016

Browse files
committed
---
yaml --- r: 31031 b: refs/heads/incoming c: 2137254 h: refs/heads/master i: 31029: 03aa0fa 31027: 1658a56 31023: 04ef41a v: v3
1 parent f6dd666 commit 9f23016

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: aca2419d55c6c5defcaa97d047da5ed7d7c8147e
9+
refs/heads/incoming: 213725407b8f70dfe9f45d636f759a8ccd9451ca
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/doc/tutorial.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,41 @@ character, such as `\n`, `\r`, and `\t`. String literals,
463463
written between double quotes, allow the same escape sequences. Rust strings
464464
may contain newlines.
465465

466+
## Constants
467+
468+
Compile-time constants are declared with `const`. All scalar types,
469+
like integers and floats, may be declared `const`, as well as fixed
470+
length vectors, static strings (more on this later), and structs.
471+
Constants may be declared in any scope and may refer to other
472+
constants. Constant declarations are not type inferred, so must always
473+
have a type annotation. By convention they are written in all capital
474+
letters.
475+
476+
~~~
477+
// Scalars can be constants
478+
const MY_PASSWORD: int = 12345;
479+
480+
// Scalar constants can be combined with other constants
481+
const MY_DOGGIES_PASSWORD: int = MY_PASSWORD + 1;
482+
483+
// Fixed-length vectors
484+
const MY_VECTORY_PASSWORD: [int * 5] = [1, 2, 3, 4, 5];
485+
486+
// Static strings
487+
const MY_STRINGY_PASSWORD: &static/str = "12345";
488+
489+
// Structs
490+
struct Password {
491+
value: int
492+
}
493+
494+
const MY_STRUCTY_PASSWORD: Password = Password { value: MY_PASSWORD };
495+
~~~
496+
497+
> ***Note:*** Support for compile-time constants and constant
498+
> evaluation is essentially added 'as needed'. You may find that
499+
> things you expect to work do not.
500+
466501
## Operators
467502

468503
Rust's set of operators contains very few surprises. Arithmetic is done with

0 commit comments

Comments
 (0)