Document adt_const_params feature in Unstable Book
This commit is contained in:
parent
13471d3b20
commit
17ba73cfa0
1 changed files with 35 additions and 0 deletions
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue