-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document
adt_const_params
feature in Unstable Book
- Loading branch information
1 parent
13471d3
commit 17ba73c
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/doc/unstable-book/src/language-features/adt-const-params.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# `adt_const_params` | ||
|
||
The tracking issue for this feature is: [#95174] | ||
|
||
[#95174]: https://github.com/rust-lang/rust/issues/95174 | ||
|
||
------------------------ | ||
|
||
Allows for using more complex types for const parameters, such as structs or enums. | ||
|
||
```rust | ||
#![feature(adt_const_params)] | ||
#![allow(incomplete_features)] | ||
|
||
use std::marker::ConstParamTy; | ||
|
||
#[derive(ConstParamTy, PartialEq, Eq)] | ||
enum Foo { | ||
A, | ||
B, | ||
C, | ||
} | ||
|
||
#[derive(ConstParamTy, PartialEq, Eq)] | ||
struct Bar { | ||
flag: bool, | ||
} | ||
|
||
fn is_foo_a_and_bar_true<const F: Foo, const B: Bar>() -> bool { | ||
match (F, B.flag) { | ||
(Foo::A, true) => true, | ||
_ => false, | ||
} | ||
} | ||
``` |