Skip to content

Commit 0e72c90

Browse files
committed
---
yaml --- r: 22323 b: refs/heads/snap-stage3 c: 2137254 h: refs/heads/master i: 22321: 14bc29c 22319: e0aee4c v: v3
1 parent 8cb0ddd commit 0e72c90

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: aca2419d55c6c5defcaa97d047da5ed7d7c8147e
4+
refs/heads/snap-stage3: 213725407b8f70dfe9f45d636f759a8ccd9451ca
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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)