File tree 1 file changed +16
-18
lines changed
1 file changed +16
-18
lines changed Original file line number Diff line number Diff line change @@ -296,6 +296,22 @@ type. It is written the same as a [constant item].
296
296
Unlike [ free] constants, associated constant definitions undergo
297
297
[ constant evaluation] only when referenced.
298
298
299
+ ``` rust
300
+ struct Struct ;
301
+
302
+ impl Struct {
303
+ const ID : i32 = 1 ;
304
+ // Definition not immediately evaluated
305
+ const PANIC : () = panic! (" compile-time panic" );
306
+ }
307
+
308
+ fn main () {
309
+ assert_eq! (1 , Struct :: ID );
310
+ // Referencing Struct::PANIC causes compilation error
311
+ // let _ = Struct::PANIC;
312
+ }
313
+ ```
314
+
299
315
### Associated Constants Examples
300
316
301
317
A basic example:
@@ -338,24 +354,6 @@ fn main() {
338
354
}
339
355
```
340
356
341
- [ Constant evaluation] timing:
342
-
343
- ``` rust
344
- struct Struct ;
345
-
346
- impl Struct {
347
- const ID : i32 = 1 ;
348
- // Definition not immediately evaluated
349
- const PANIC : () = panic! (" compile-time panic" );
350
- }
351
-
352
- fn main () {
353
- assert_eq! (1 , Struct :: ID );
354
- // Referencing Struct::PANIC causes compilation error
355
- // let _ = Struct::PANIC;
356
- }
357
- ```
358
-
359
357
[ _ConstantItem_ ] : constant-items.md
360
358
[ _Function_ ] : functions.md
361
359
[ _MacroInvocationSemi_ ] : ../macros.md#macro-invocation
You can’t perform that action at this time.
0 commit comments