Rust unstable book: basic desc and example for const_fn.
This commit is contained in:
parent
fd182c4010
commit
e06c51553d
2 changed files with 20 additions and 1 deletions
|
|
@ -6,5 +6,24 @@ The tracking issue for this feature is: [#24111]
|
|||
|
||||
------------------------
|
||||
|
||||
The `const_fn` feature allows marking free functions and inherent methods as
|
||||
`const`, enabling them to be called in constants contexts, with constant
|
||||
arguments.
|
||||
|
||||
## Examples
|
||||
|
||||
```rust
|
||||
#![feature(const_fn)]
|
||||
|
||||
const fn double(x: i32) -> i32 {
|
||||
x * 2
|
||||
}
|
||||
|
||||
const FIVE: i32 = 5;
|
||||
const TEN: i32 = double(FIVE);
|
||||
|
||||
fn main() {
|
||||
assert_eq!(5, FIVE);
|
||||
assert_eq!(10, TEN);
|
||||
}
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue