Skip to content

Commit e06c515

Browse files
committed
Rust unstable book: basic desc and example for const_fn.
1 parent fd182c4 commit e06c515

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/doc/unstable-book/src/const-fn.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,24 @@ The tracking issue for this feature is: [#24111]
66

77
------------------------
88

9+
The `const_fn` feature allows marking free functions and inherent methods as
10+
`const`, enabling them to be called in constants contexts, with constant
11+
arguments.
912

13+
## Examples
1014

15+
```rust
16+
#![feature(const_fn)]
17+
18+
const fn double(x: i32) -> i32 {
19+
x * 2
20+
}
21+
22+
const FIVE: i32 = 5;
23+
const TEN: i32 = double(FIVE);
24+
25+
fn main() {
26+
assert_eq!(5, FIVE);
27+
assert_eq!(10, TEN);
28+
}
29+
```

0 commit comments

Comments
 (0)