File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed 
src/doc/unstable-book/src/language-features Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ # ` inline_const `  
2+ 
3+ The tracking issue for this feature is: [ #76001  ] 
4+ 
5+ ------ 
6+ 
7+ This feature allows you to use inline constant expressions. For example, you can
8+ turn this code:
9+ 
10+ ``` rust 
11+ # fn  add_one (x :  i32 ) ->  i32  { x  +  1  }
12+ const  MY_COMPUTATION :  i32  =  1  +  2  *  3  /  4 ;
13+ 
14+ fn  main () {
15+     let  x  =  add_one (MY_COMPUTATION );
16+ }
17+ ``` 
18+ 
19+ into this code:
20+ 
21+ ``` rust 
22+ #![feature(inline_const)]
23+ 
24+ # fn  add_one (x :  i32 ) ->  i32  { x  +  1  }
25+ fn  main () {
26+     let  x  =  add_one (const  { 1  +  2  *  3  /  4  });
27+ }
28+ ``` 
29+ 
30+ You can also use inline constant expressions in patterns:
31+ 
32+ ``` rust 
33+ #![feature(inline_const)]
34+ 
35+ const  fn  one () ->  i32  { 1  }
36+ 
37+ let  some_int  =  3 ;
38+ match  some_int  {
39+     const  { 1  +  2  } =>  println! (" Matched 1 + 2"  ),
40+     const  { one () } =>  println! (" Matched const fn returning 1"  ),
41+     _  =>  println! (" Didn't match anything :("  ),
42+ }
43+ ``` 
44+ 
45+ [ #76001 ] : https://github.com/rust-lang/rust/issues/76001 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments