-
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.
Auto merge of #53751 - F001:tuple-struct-self-ctor, r=petrochenkov,va…
…rkor Implement RFC 2302: tuple_struct_self_ctor Tracking issue: #51994
- Loading branch information
Showing
27 changed files
with
469 additions
and
149 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/doc/unstable-book/src/language-features/self-struct-ctor.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,33 @@ | ||
# `self_struct_ctor` | ||
|
||
The tracking issue for this feature is: [#51994] | ||
[#51994]: https://github.com/rust-lang/rust/issues/51994 | ||
|
||
------------------------ | ||
|
||
The `self_struct_ctor` feature gate lets you use the special `Self` | ||
identifier as a constructor and a pattern. | ||
|
||
A simple example is: | ||
|
||
```rust | ||
#![feature(self_struct_ctor)] | ||
|
||
struct ST(i32, i32); | ||
|
||
impl ST { | ||
fn new() -> Self { | ||
ST(0, 1) | ||
} | ||
|
||
fn ctor() -> Self { | ||
Self(1,2) // constructed by `Self`, it is the same as `ST(1, 2)` | ||
} | ||
|
||
fn pattern(self) { | ||
match self { | ||
Self(x, y) => println!("{} {}", x, y), // used as a pattern | ||
} | ||
} | ||
} | ||
``` |
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
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
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
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
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
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
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
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
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
Oops, something went wrong.