diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-03-11 17:10:05 -0500 |
|---|---|---|
| committer | Corey Farwell <coreyf@rwell.org> | 2017-03-13 21:35:52 -0400 |
| commit | e06c51553ddc202a79f2c0b76822ad56c4a30f80 (patch) | |
| tree | 6bfb2d6313464e428fb7046795d2e4c7213e44fb | |
| parent | fd182c4010b5aee72d070b15e90c98cb0fdc3776 (diff) | |
| download | rust-e06c51553ddc202a79f2c0b76822ad56c4a30f80.tar.gz rust-e06c51553ddc202a79f2c0b76822ad56c4a30f80.zip | |
Rust unstable book: basic desc and example for `const_fn`.
| m--------- | cargo | 0 | ||||
| -rw-r--r-- | src/doc/unstable-book/src/const-fn.md | 19 |
2 files changed, 19 insertions, 0 deletions
diff --git a/cargo b/cargo -Subproject 4a3c0a63b07e9a4feb41cb11de37c92a09db5a6 +Subproject 5f3b9c4c6a7be1f177d6024cb83d150b6479148 diff --git a/src/doc/unstable-book/src/const-fn.md b/src/doc/unstable-book/src/const-fn.md index 9b7942c408a..d5a22436838 100644 --- a/src/doc/unstable-book/src/const-fn.md +++ b/src/doc/unstable-book/src/const-fn.md @@ -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); +} +``` |
