diff options
| author | SparrowLii <liyuan179@huawei.com> | 2021-10-19 11:08:12 +0800 |
|---|---|---|
| committer | SparrowLii <liyuan179@huawei.com> | 2021-10-28 14:17:15 +0800 |
| commit | 7bde18a0f3dc52754eb52d09da0bc259b1a0e757 (patch) | |
| tree | 932856e492ecc8144b95f7535a6868a503e52cf7 /src/doc | |
| parent | 41d8c94d454f23239715a6433df79e46df8bce04 (diff) | |
implement type-changing-struct-update
put the test dir in test/ui/rfcs
Diffstat (limited to 'src/doc')
| -rw-r--r-- | src/doc/unstable-book/src/language-features/type-changing-struct-update.md | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/doc/unstable-book/src/language-features/type-changing-struct-update.md b/src/doc/unstable-book/src/language-features/type-changing-struct-update.md new file mode 100644 index 00000000000..9909cf35b5b --- /dev/null +++ b/src/doc/unstable-book/src/language-features/type-changing-struct-update.md @@ -0,0 +1,33 @@ +# `type_changing_struct_update` + +The tracking issue for this feature is: [#86555] + +[#86555]: https://github.com/rust-lang/rust/issues/86555 + +------------------------ + +This implements [RFC2528]. When turned on, you can create instances of the same struct +that have different generic type or lifetime parameters. + +[RFC2528]: https://github.com/rust-lang/rfcs/blob/master/text/2528-type-changing-struct-update-syntax.md + +```rust +#![allow(unused_variables, dead_code)] +#![feature(type_changing_struct_update)] + +fn main () { + struct Foo<T, U> { + field1: T, + field2: U, + } + + let base: Foo<String, i32> = Foo { + field1: String::from("hello"), + field2: 1234, + }; + let updated: Foo<f64, i32> = Foo { + field1: 3.14, + ..base + }; +} +``` |
