Skip to content

Commit 3acef7a

Browse files
author
Alexander Regueiro
committed
Added chapter to Unstable Book.
1 parent 75d1e03 commit 3acef7a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# `type_alias_enum_variants`
2+
3+
The tracking issue for this feature is: [#49683]
4+
5+
[#49683]: https://github.com/rust-lang/rust/issues/49683
6+
7+
------------------------
8+
9+
The `type_alias_enum_variants` feature enables the use of variants on type
10+
aliases that refer to enums, as both a constructor and a pattern. That is,
11+
it allows for the syntax `EnumAlias::Variant`, which behaves exactly the same
12+
as `Enum::Variant` (assuming that `EnumAlias` is an alias for some enum type
13+
`Enum`).
14+
15+
Note that since `Self` exists as a type alias, this feature also enables the
16+
use of the syntax `Self::Variant` within an impl block for an enum type.
17+
18+
```rust
19+
#![feature(type_alias_enum_variants)]
20+
21+
enum Foo {
22+
Bar(i32),
23+
Baz { i: i32 },
24+
}
25+
26+
type Alias = Foo;
27+
28+
fn main() {
29+
let t = Alias::Bar(0);
30+
let t = Alias::Baz { i: 0 };
31+
match t {
32+
Alias::Bar(_i) => {}
33+
Alias::Baz { i: _i } => {}
34+
}
35+
}
36+
```

0 commit comments

Comments
 (0)