File tree 1 file changed +36
-0
lines changed
src/doc/unstable-book/src/language-features
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
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
+ ```
You can’t perform that action at this time.
0 commit comments