@@ -107,18 +107,20 @@ mod break_keyword {}
107
107
/// Sometimes a certain value is used many times throughout a program, and it can become
108
108
/// inconvenient to copy it over and over. What's more, it's not always possible or desirable to
109
109
/// make it a variable that gets carried around to each function that needs it. In these cases, the
110
- /// `const` keyword provides a convenient alternative to code duplication.
110
+ /// `const` keyword provides a convenient alternative to code duplication:
111
111
///
112
112
/// ```rust
113
113
/// const THING: u32 = 0xABAD1DEA;
114
114
///
115
115
/// let foo = 123 + THING;
116
116
/// ```
117
117
///
118
- /// Constants must be explicitly typed, unlike with `let` you can't ignore its type and let the
119
- /// compiler figure it out. Any constant value can be defined in a const, which in practice happens
120
- /// to be most things that would be reasonable to have a constant (barring `const fn`s). For
121
- /// example, you can't have a File as a `const`.
118
+ /// Constants must be explicitly typed; unlike with `let`, you can't ignore their type and let the
119
+ /// compiler figure it out. Any constant value can be defined in a `const`, which in practice happens
120
+ /// to be most things that would be reasonable to have in a constant (barring `const fn`s). For
121
+ /// example, you can't have a [`File`] as a `const`.
122
+ ///
123
+ /// [`File`]: crate::fs::File
122
124
///
123
125
/// The only lifetime allowed in a constant is `'static`, which is the lifetime that encompasses
124
126
/// all others in a Rust program. For example, if you wanted to define a constant string, it would
@@ -128,27 +130,27 @@ mod break_keyword {}
128
130
/// const WORDS: &'static str = "hello rust!";
129
131
/// ```
130
132
///
131
- /// Thanks to static lifetime elision, you usually don't have to explicitly use 'static:
133
+ /// Thanks to static lifetime elision, you usually don't have to explicitly use ` 'static` :
132
134
///
133
135
/// ```rust
134
136
/// const WORDS: &str = "hello convenience!";
135
137
/// ```
136
138
///
137
139
/// `const` items looks remarkably similar to `static` items, which introduces some confusion as
138
140
/// to which one should be used at which times. To put it simply, constants are inlined wherever
139
- /// they're used, making using them identical to simply replacing the name of the const with its
140
- /// value. Static variables on the other hand point to a single location in memory, which all
141
+ /// they're used, making using them identical to simply replacing the name of the ` const` with its
142
+ /// value. Static variables, on the other hand, point to a single location in memory, which all
141
143
/// accesses share. This means that, unlike with constants, they can't have destructors, and act as
142
144
/// a single value across the entire codebase.
143
145
///
144
- /// Constants, as with statics, should always be in SCREAMING_SNAKE_CASE.
146
+ /// Constants, like statics, should always be in ` SCREAMING_SNAKE_CASE` .
145
147
///
146
148
/// The `const` keyword is also used in raw pointers in combination with `mut`, as seen in `*const
147
- /// T` and `*mut T`. More about that can be read at the [pointer] primitive part of the Rust docs .
149
+ /// T` and `*mut T`. More about `const` as used in raw pointers can be read at the Rust docs for the [pointer primitive] .
148
150
///
149
- /// For more detail on `const`, see the [Rust Book] or the [Reference]
151
+ /// For more detail on `const`, see the [Rust Book] or the [Reference].
150
152
///
151
- /// [pointer]: primitive.pointer.html
153
+ /// [pointer primitive ]: primitive.pointer.html
152
154
/// [Rust Book]:
153
155
/// ../book/ch03-01-variables-and-mutability.html#differences-between-variables-and-constants
154
156
/// [Reference]: ../reference/items/constant-items.html
0 commit comments