6
6
> ` = ` [ _ Expression_ ] ` ; `
7
7
8
8
A * static item* is similar to a [ constant] , except that it represents a precise
9
- memory location in the program. A static is never "inlined" at the usage site,
10
- and all references to it refer to the same memory location. Static items have
11
- the ` static ` lifetime, which outlives all other lifetimes in a Rust program.
12
- Static items may be placed in read-only memory if the type is not [ interior
13
- mutable ] . Static items do not call ` drop ` at the end of the program.
9
+ memory location in the program. All references to the static refer to the same
10
+ memory location. Static items have the ` static ` lifetime, which outlives all
11
+ other lifetimes in a Rust program. Non- ` mut ` static items that contain a type
12
+ that is not [ interior mutable ] may be placed in read-only memory. Static items
13
+ do not call [ ` drop ` ] at the end of the program.
14
14
15
15
All access to a static is safe, but there are a number of restrictions on
16
16
statics:
17
17
18
18
* The type must have the ` Sync ` trait bound to allow thread-safe access.
19
- * Statics allow using paths to statics in the
20
- [ constant-expression] ( expressions.html#constant-expressions ) used to
19
+ * Statics allow using paths to statics in the [ constant-expression] used to
21
20
initialize them, but statics may not refer to other statics by value, only
22
21
through a reference.
23
22
* Constants cannot refer to statics.
@@ -33,7 +32,7 @@ modifications to a mutable static are safe with respect to other threads
33
32
running in the same process.
34
33
35
34
Mutable statics are still very useful, however. They can be used with C
36
- libraries and can also be bound from C libraries ( in an ` extern ` block) .
35
+ libraries and can also be bound from C libraries in an ` extern ` block.
37
36
38
37
``` rust
39
38
# fn atomic_add (_ : & mut u32 , _ : u32 ) -> u32 { 2 }
@@ -66,10 +65,12 @@ item. Constants should, in general, be preferred over statics unless one of the
66
65
following are true:
67
66
68
67
* Large amounts of data are being stored
69
- * The single-address or non-inlining property of statics is required.
68
+ * The single-address property of statics is required.
70
69
* Interior mutability is required.
71
70
72
71
[ constant ] : items/constant-items.html
72
+ [ `drop` ] : destructors.html
73
+ [ constant expression ] : expressions.html#constant-expressions
73
74
[ interior mutable ] : interior-mutability.html
74
75
[ IDENTIFIER ] : identifiers.html
75
76
[ _Type_ ] : types.html
0 commit comments