From 8c8324d30d4712f272e3ac68365015841cd0f790 Mon Sep 17 00:00:00 2001 From: redradist Date: Wed, 24 Jun 2020 12:17:25 +0300 Subject: [PATCH 01/12] Initial description of self life-time propousal --- text/0000-self-life-time.md | 171 ++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 text/0000-self-life-time.md diff --git a/text/0000-self-life-time.md b/text/0000-self-life-time.md new file mode 100644 index 00000000000..95f33410e52 --- /dev/null +++ b/text/0000-self-life-time.md @@ -0,0 +1,171 @@ +- Feature Name: self life-time +- Start Date: 2020-06-24 +- RFC PR: [rust-lang/rfcs#0000](https://github.com/rust-lang/rfcs/pull/0000) +- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000) + +# Summary +[summary]: #summary + +New 'self named life-time that implicitly bound to life-time of current structure + +# Motivation +[motivation]: #motivation + +Moptivation is for simplification iterative development and improving refactoring of the code + +Sometimes during refactoring such code: +```rust +struct CompositeObject { + obj: SomeType, +} + +struct BigObject { + composite_obj: CompositeObject, + count: i32, +} + +struct Application { + big_obj: BigObject, +} +``` + +developer decides to make obj of SomeType as reference in CompositeObject type: +```rust +struct CompositeObject<'a> { + obj: &'a SomeType, +} + +struct BigObject<'a> { + composite_obj: CompositeObject<'a>, + count: i32, +} + +struct Application<'a> { + big_obj: BigObject<'a>, +} +``` +Everywhere in composition hierarchy I need to write 'a ... most of the times it is just boilerplate code ... + +What if instead of writing manually we will introduce the 'self life-time: +```rust +struct CompositeObject { + obj: &'self SomeType, +} + +struct BigObject { + composite_obj: CompositeObject, + count: i32, +} + +struct Application { + big_obj: BigObject, +} +``` + +Code much simpler and more maintainable than fighting with named life-times in composite hierarchy + +Compiler underhood will generate the following code: +```rust +struct CompositeObject<'self> { // 'self is implicit life-time of CompositeObject + obj: &'self SomeType, +} + +struct BigObject<'self> { // 'self is implicit life-time of BigObject + composite_obj: CompositeObject<'self>, // Assign 'self of BigObject to CompositeObject + count: i32, +} + +struct Application<'self> { // 'self is implicit life-time of Application + big_obj: BigObject<'self>, // Assign 'self of Application to BigObject +} +``` + +On user side call should be like this: +```rust +fn make_app(config: &Config) -> App; +``` +or +```rust +fn make_app(config: &Config) -> App<'_>; +``` + +# Guide-level explanation +[guide-level-explanation]: #guide-level-explanation + +Explain the proposal as if it was already included in the language and you were teaching it to another Rust programmer. That generally means: + +- Introducing new named concepts. +- Explaining the feature largely in terms of examples. +- Explaining how Rust programmers should *think* about the feature, and how it should impact the way they use Rust. It should explain the impact as concretely as possible. +- If applicable, provide sample error messages, deprecation warnings, or migration guidance. +- If applicable, describe the differences between teaching this to existing Rust programmers and new Rust programmers. + +For implementation-oriented RFCs (e.g. for compiler internals), this section should focus on how compiler contributors should think about the change, and give examples of its concrete impact. For policy RFCs, this section should provide an example-driven introduction to the policy, and explain its impact in concrete terms. + +# Reference-level explanation +[reference-level-explanation]: #reference-level-explanation + +This is the technical portion of the RFC. Explain the design in sufficient detail that: + +- Its interaction with other features is clear. +- It is reasonably clear how the feature would be implemented. +- Corner cases are dissected by example. + +The section should return to the examples given in the previous section, and explain more fully how the detailed proposal makes those examples work. + +# Drawbacks +[drawbacks]: #drawbacks + +Why should we *not* do this? + +# Rationale and alternatives +[rationale-and-alternatives]: #rationale-and-alternatives + +- Why is this design the best in the space of possible designs? +- What other designs have been considered and what is the rationale for not choosing them? +- What is the impact of not doing this? + +# Prior art +[prior-art]: #prior-art + +Discuss prior art, both the good and the bad, in relation to this proposal. +A few examples of what this can include are: + +- For language, library, cargo, tools, and compiler proposals: Does this feature exist in other programming languages and what experience have their community had? +- For community proposals: Is this done by some other community and what were their experiences with it? +- For other teams: What lessons can we learn from what other communities have done here? +- Papers: Are there any published papers or great posts that discuss this? If you have some relevant papers to refer to, this can serve as a more detailed theoretical background. + +This section is intended to encourage you as an author to think about the lessons from other languages, provide readers of your RFC with a fuller picture. +If there is no prior art, that is fine - your ideas are interesting to us whether they are brand new or if it is an adaptation from other languages. + +Note that while precedent set by other languages is some motivation, it does not on its own motivate an RFC. +Please also take into consideration that rust sometimes intentionally diverges from common language features. + +# Unresolved questions +[unresolved-questions]: #unresolved-questions + +- What parts of the design do you expect to resolve through the RFC process before this gets merged? +- What parts of the design do you expect to resolve through the implementation of this feature before stabilization? +- What related issues do you consider out of scope for this RFC that could be addressed in the future independently of the solution that comes out of this RFC? + +# Future possibilities +[future-possibilities]: #future-possibilities + +Think about what the natural extension and evolution of your proposal would +be and how it would affect the language and project as a whole in a holistic +way. Try to use this section as a tool to more fully consider all possible +interactions with the project and language in your proposal. +Also consider how the this all fits into the roadmap for the project +and of the relevant sub-team. + +This is also a good place to "dump ideas", if they are out of scope for the +RFC you are writing but otherwise related. + +If you have tried and cannot think of any future possibilities, +you may simply state that you cannot think of anything. + +Note that having something written down in the future-possibilities section +is not a reason to accept the current or a future RFC; such notes should be +in the section on motivation or rationale in this or subsequent RFCs. +The section merely provides additional information. From 8a3bb000630b82bbd4c289b464b831cc5d34c629 Mon Sep 17 00:00:00 2001 From: redradist Date: Wed, 24 Jun 2020 23:51:15 +0300 Subject: [PATCH 02/12] Second iteration of self life-time propousal --- text/0000-self-life-time.md | 74 ++----------------------------------- 1 file changed, 3 insertions(+), 71 deletions(-) diff --git a/text/0000-self-life-time.md b/text/0000-self-life-time.md index 95f33410e52..1a07d4571eb 100644 --- a/text/0000-self-life-time.md +++ b/text/0000-self-life-time.md @@ -4,12 +4,10 @@ - Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000) # Summary -[summary]: #summary New 'self named life-time that implicitly bound to life-time of current structure # Motivation -[motivation]: #motivation Moptivation is for simplification iterative development and improving refactoring of the code @@ -89,83 +87,17 @@ or fn make_app(config: &Config) -> App<'_>; ``` -# Guide-level explanation -[guide-level-explanation]: #guide-level-explanation - -Explain the proposal as if it was already included in the language and you were teaching it to another Rust programmer. That generally means: - -- Introducing new named concepts. -- Explaining the feature largely in terms of examples. -- Explaining how Rust programmers should *think* about the feature, and how it should impact the way they use Rust. It should explain the impact as concretely as possible. -- If applicable, provide sample error messages, deprecation warnings, or migration guidance. -- If applicable, describe the differences between teaching this to existing Rust programmers and new Rust programmers. - -For implementation-oriented RFCs (e.g. for compiler internals), this section should focus on how compiler contributors should think about the change, and give examples of its concrete impact. For policy RFCs, this section should provide an example-driven introduction to the policy, and explain its impact in concrete terms. - -# Reference-level explanation -[reference-level-explanation]: #reference-level-explanation - -This is the technical portion of the RFC. Explain the design in sufficient detail that: - -- Its interaction with other features is clear. -- It is reasonably clear how the feature would be implemented. -- Corner cases are dissected by example. - -The section should return to the examples given in the previous section, and explain more fully how the detailed proposal makes those examples work. - # Drawbacks [drawbacks]: #drawbacks -Why should we *not* do this? +It could conflict with existing 'self life-time in some crate # Rationale and alternatives [rationale-and-alternatives]: #rationale-and-alternatives -- Why is this design the best in the space of possible designs? -- What other designs have been considered and what is the rationale for not choosing them? -- What is the impact of not doing this? +This design will help developers to iteravly play with library design, which should increase qualitty of the final library or application # Prior art [prior-art]: #prior-art -Discuss prior art, both the good and the bad, in relation to this proposal. -A few examples of what this can include are: - -- For language, library, cargo, tools, and compiler proposals: Does this feature exist in other programming languages and what experience have their community had? -- For community proposals: Is this done by some other community and what were their experiences with it? -- For other teams: What lessons can we learn from what other communities have done here? -- Papers: Are there any published papers or great posts that discuss this? If you have some relevant papers to refer to, this can serve as a more detailed theoretical background. - -This section is intended to encourage you as an author to think about the lessons from other languages, provide readers of your RFC with a fuller picture. -If there is no prior art, that is fine - your ideas are interesting to us whether they are brand new or if it is an adaptation from other languages. - -Note that while precedent set by other languages is some motivation, it does not on its own motivate an RFC. -Please also take into consideration that rust sometimes intentionally diverges from common language features. - -# Unresolved questions -[unresolved-questions]: #unresolved-questions - -- What parts of the design do you expect to resolve through the RFC process before this gets merged? -- What parts of the design do you expect to resolve through the implementation of this feature before stabilization? -- What related issues do you consider out of scope for this RFC that could be addressed in the future independently of the solution that comes out of this RFC? - -# Future possibilities -[future-possibilities]: #future-possibilities - -Think about what the natural extension and evolution of your proposal would -be and how it would affect the language and project as a whole in a holistic -way. Try to use this section as a tool to more fully consider all possible -interactions with the project and language in your proposal. -Also consider how the this all fits into the roadmap for the project -and of the relevant sub-team. - -This is also a good place to "dump ideas", if they are out of scope for the -RFC you are writing but otherwise related. - -If you have tried and cannot think of any future possibilities, -you may simply state that you cannot think of anything. - -Note that having something written down in the future-possibilities section -is not a reason to accept the current or a future RFC; such notes should be -in the section on motivation or rationale in this or subsequent RFCs. -The section merely provides additional information. +There was disscutions on this topic in https://internals.rust-lang.org/t/simplification-reference-life-time/12224/20 From 3ff7ef83b951c20caf98860b1f680e8ce8416d8a Mon Sep 17 00:00:00 2001 From: redradist Date: Wed, 24 Jun 2020 23:56:16 +0300 Subject: [PATCH 03/12] Fix wording in RFCS --- text/0000-self-life-time.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/text/0000-self-life-time.md b/text/0000-self-life-time.md index 1a07d4571eb..a1ed765277a 100644 --- a/text/0000-self-life-time.md +++ b/text/0000-self-life-time.md @@ -9,7 +9,7 @@ New 'self named life-time that implicitly bound to life-time of current structur # Motivation -Moptivation is for simplification iterative development and improving refactoring of the code +Motivation is to simplify iterative development and improving refactoring of the code Sometimes during refactoring such code: ```rust @@ -80,11 +80,11 @@ struct Application<'self> { // 'self is implicit life-time of Application On user side call should be like this: ```rust -fn make_app(config: &Config) -> App; +fn make_app(config: &Config) -> Application; ``` or ```rust -fn make_app(config: &Config) -> App<'_>; +fn make_app(config: &Config) -> Application<'_>; ``` # Drawbacks From 4558622704231f1754c362ec5c886a2a80fda18f Mon Sep 17 00:00:00 2001 From: redradist Date: Sat, 27 Jun 2020 08:56:27 +0300 Subject: [PATCH 04/12] Changed wording in RFC --- text/0000-self-life-time.md | 55 +++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/text/0000-self-life-time.md b/text/0000-self-life-time.md index a1ed765277a..ee87aa2b012 100644 --- a/text/0000-self-life-time.md +++ b/text/0000-self-life-time.md @@ -1,11 +1,11 @@ -- Feature Name: self life-time +- Feature Name: Hierarchic anonymous life-time - Start Date: 2020-06-24 - RFC PR: [rust-lang/rfcs#0000](https://github.com/rust-lang/rfcs/pull/0000) - Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000) # Summary -New 'self named life-time that implicitly bound to life-time of current structure +New use of anonymous life-time '_ that implicitly added to current structure # Motivation @@ -44,10 +44,10 @@ struct Application<'a> { ``` Everywhere in composition hierarchy I need to write 'a ... most of the times it is just boilerplate code ... -What if instead of writing manually we will introduce the 'self life-time: +What if instead of writing manually we will specify reference fields with anonymous life-time: ```rust struct CompositeObject { - obj: &'self SomeType, + obj: &'_ SomeType, } struct BigObject { @@ -64,17 +64,50 @@ Code much simpler and more maintainable than fighting with named life-times in c Compiler underhood will generate the following code: ```rust -struct CompositeObject<'self> { // 'self is implicit life-time of CompositeObject - obj: &'self SomeType, +struct CompositeObject<'anon> { // 'anon is implicitly added life-time + obj: &'anon SomeType, } -struct BigObject<'self> { // 'self is implicit life-time of BigObject - composite_obj: CompositeObject<'self>, // Assign 'self of BigObject to CompositeObject +struct BigObject<'anon> { // 'anon is implicitly added life-time + composite_obj: CompositeObject<'anon>, // 'anon is implicitly used here count: i32, } -struct Application<'self> { // 'self is implicit life-time of Application - big_obj: BigObject<'self>, // Assign 'self of Application to BigObject +struct Application<'anon> { // 'anon is implicitly added life-time + big_obj: BigObject<'anon>, // 'anon is implicitly used here +} +``` + +Take a look at example with multiple anonymose life-times: +```rust +struct CompositeObject { + obj0: &'_ SomeType, + obj1: &'_ SomeType, +} + +struct BigObject { + composite_obj: CompositeObject, + count: i32, +} + +struct Application { + big_obj: BigObject, +} +``` +code will be translated to: +```rust +struct CompositeObject<'anon0, 'anon1> { // 'anon0 and 'anon1 are implicitly added life-times + obj0: &'anon0 SomeType, + obj1: &'anon1 SomeType, +} + +struct BigObject<'anon0, 'anon1> { // 'anon is implicitly added life-time + composite_obj: CompositeObject<'anon0, 'anon1>, // 'anon is implicitly used here + count: i32, +} + +struct Application<'anon0, 'anon1> { // 'anon is implicitly added life-time + big_obj: BigObject<'anon0, 'anon1>, // 'anon is implicitly used here } ``` @@ -90,7 +123,7 @@ fn make_app(config: &Config) -> Application<'_>; # Drawbacks [drawbacks]: #drawbacks -It could conflict with existing 'self life-time in some crate +Not known at the current time # Rationale and alternatives [rationale-and-alternatives]: #rationale-and-alternatives From bb9b71141864fe0b277d28afb38cb8c6f12e4b66 Mon Sep 17 00:00:00 2001 From: redradist Date: Sat, 27 Jun 2020 08:57:27 +0300 Subject: [PATCH 05/12] Renamed RFC 0000-self-life-time.md -> 0000-hierarchic-anonymous-life-time.md --- ...0-self-life-time.md => 0000-hierarchic-anonymous-life-time.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename text/{0000-self-life-time.md => 0000-hierarchic-anonymous-life-time.md} (100%) diff --git a/text/0000-self-life-time.md b/text/0000-hierarchic-anonymous-life-time.md similarity index 100% rename from text/0000-self-life-time.md rename to text/0000-hierarchic-anonymous-life-time.md From 5044d33639b05c02478bc90828693c1309a66254 Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 30 Jun 2020 18:01:37 +0300 Subject: [PATCH 06/12] Update text/0000-hierarchic-anonymous-life-time.md Co-authored-by: Ivan Tham --- text/0000-hierarchic-anonymous-life-time.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/0000-hierarchic-anonymous-life-time.md b/text/0000-hierarchic-anonymous-life-time.md index ee87aa2b012..a25680b7583 100644 --- a/text/0000-hierarchic-anonymous-life-time.md +++ b/text/0000-hierarchic-anonymous-life-time.md @@ -5,7 +5,7 @@ # Summary -New use of anonymous life-time '_ that implicitly added to current structure +New use of anonymous life-time `'_` that implicitly added to current structure. # Motivation From 04a88c36c0dcf386f301fe4340237c65ebd42e0c Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 2 Jul 2020 20:16:30 +0300 Subject: [PATCH 07/12] Update text/0000-hierarchic-anonymous-life-time.md Co-authored-by: Ivan Tham --- text/0000-hierarchic-anonymous-life-time.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/text/0000-hierarchic-anonymous-life-time.md b/text/0000-hierarchic-anonymous-life-time.md index a25680b7583..cb4934c8a1b 100644 --- a/text/0000-hierarchic-anonymous-life-time.md +++ b/text/0000-hierarchic-anonymous-life-time.md @@ -46,17 +46,17 @@ Everywhere in composition hierarchy I need to write 'a ... most of the times it What if instead of writing manually we will specify reference fields with anonymous life-time: ```rust -struct CompositeObject { - obj: &'_ SomeType, +struct City { + name: &'_ str, } -struct BigObject { - composite_obj: CompositeObject, - count: i32, +struct State { + city: Vec, + covid_deaths: u32, } -struct Application { - big_obj: BigObject, +struct Country { + state: Vec, } ``` From 0260279193a92a4d0f7b0beac285f62fbc0caff1 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 2 Jul 2020 20:17:38 +0300 Subject: [PATCH 08/12] Update text/0000-hierarchic-anonymous-life-time.md Co-authored-by: Ivan Tham --- text/0000-hierarchic-anonymous-life-time.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/text/0000-hierarchic-anonymous-life-time.md b/text/0000-hierarchic-anonymous-life-time.md index cb4934c8a1b..0ff4c34b067 100644 --- a/text/0000-hierarchic-anonymous-life-time.md +++ b/text/0000-hierarchic-anonymous-life-time.md @@ -13,17 +13,17 @@ Motivation is to simplify iterative development and improving refactoring of the Sometimes during refactoring such code: ```rust -struct CompositeObject { - obj: SomeType, +struct City { + name: String, } -struct BigObject { - composite_obj: CompositeObject, - count: i32, +struct State { + city: Vec, + covid_deaths: u32, } -struct Application { - big_obj: BigObject, +struct Country { + state: Vec, } ``` From 233839a112a580dc5e987489a19213ce21443369 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 2 Jul 2020 20:31:37 +0300 Subject: [PATCH 09/12] Update 0000-hierarchic-anonymous-life-time.md Update according discussion in comments --- text/0000-hierarchic-anonymous-life-time.md | 43 ++++++++++++++------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/text/0000-hierarchic-anonymous-life-time.md b/text/0000-hierarchic-anonymous-life-time.md index 0ff4c34b067..00dbf35fc22 100644 --- a/text/0000-hierarchic-anonymous-life-time.md +++ b/text/0000-hierarchic-anonymous-life-time.md @@ -46,35 +46,50 @@ Everywhere in composition hierarchy I need to write 'a ... most of the times it What if instead of writing manually we will specify reference fields with anonymous life-time: ```rust -struct City { - name: &'_ str, +struct City& { + name: &str, } -struct State { - city: Vec, +struct State& { + cities: Vec, covid_deaths: u32, } -struct Country { - state: Vec, +struct Country& { + state: Vec, } ``` -Code much simpler and more maintainable than fighting with named life-times in composite hierarchy +With this solution developer could just declar with `["&"]` name that this structure could have used some references, just be attentive +Developer just could anons that this structure will use references some times without even using references inside: +```rust +struct City& { + name: String, +} + +struct State& { + cities: Vec, + covid_deaths: u32, +} + +struct Country& { + state: Vec, +} +``` Compiler underhood will generate the following code: ```rust -struct CompositeObject<'anon> { // 'anon is implicitly added life-time - obj: &'anon SomeType, +struct City<'anon> { // 'anon is implicitly added life-time + obj: &'anon str, } -struct BigObject<'anon> { // 'anon is implicitly added life-time - composite_obj: CompositeObject<'anon>, // 'anon is implicitly used here - count: i32, +struct State<'anon> { // 'anon is implicitly added life-time + composite_obj: Vec>, // 'anon is implicitly used here + covid_deaths: i32, } -struct Application<'anon> { // 'anon is implicitly added life-time - big_obj: BigObject<'anon>, // 'anon is implicitly used here +struct Country<'anon> { // 'anon is implicitly added life-time + state: Vec, // 'anon is implicitly used here } ``` From f6caad2bae758c5b3c25c315c81eb1f22378c799 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 2 Jul 2020 20:36:52 +0300 Subject: [PATCH 10/12] Update text/0000-hierarchic-anonymous-life-time.md Co-authored-by: Ivan Tham --- text/0000-hierarchic-anonymous-life-time.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/text/0000-hierarchic-anonymous-life-time.md b/text/0000-hierarchic-anonymous-life-time.md index 00dbf35fc22..c1eee997831 100644 --- a/text/0000-hierarchic-anonymous-life-time.md +++ b/text/0000-hierarchic-anonymous-life-time.md @@ -27,19 +27,19 @@ struct Country { } ``` -developer decides to make obj of SomeType as reference in CompositeObject type: +developer decides to make an inner item a reference: ```rust -struct CompositeObject<'a> { - obj: &'a SomeType, +struct City<'a> { + name: &'a str, } -struct BigObject<'a> { - composite_obj: CompositeObject<'a>, - count: i32, +struct State<'a> { + city: Vec>, + covid_deaths: u32, } -struct Application<'a> { - big_obj: BigObject<'a>, +struct Country<'a> { + state: Vec>, } ``` Everywhere in composition hierarchy I need to write 'a ... most of the times it is just boilerplate code ... From 585fb1f9045cf3b36bcd4f5ae85be9d3081123e9 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 2 Jul 2020 20:37:39 +0300 Subject: [PATCH 11/12] Update 0000-hierarchic-anonymous-life-time.md --- text/0000-hierarchic-anonymous-life-time.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/text/0000-hierarchic-anonymous-life-time.md b/text/0000-hierarchic-anonymous-life-time.md index c1eee997831..9c11c5f56a2 100644 --- a/text/0000-hierarchic-anonymous-life-time.md +++ b/text/0000-hierarchic-anonymous-life-time.md @@ -79,16 +79,16 @@ struct Country& { Compiler underhood will generate the following code: ```rust -struct City<'anon> { // 'anon is implicitly added life-time +struct City&<'anon> { // 'anon is implicitly added life-time obj: &'anon str, } -struct State<'anon> { // 'anon is implicitly added life-time - composite_obj: Vec>, // 'anon is implicitly used here +struct State&<'anon> { // 'anon is implicitly added life-time + composite_obj: Vec>, // 'anon is implicitly used here covid_deaths: i32, } -struct Country<'anon> { // 'anon is implicitly added life-time +struct Country&<'anon> { // 'anon is implicitly added life-time state: Vec, // 'anon is implicitly used here } ``` From cf4f0c15b262dae27ce963fa68bbffcf10612e6a Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 3 Jul 2020 10:44:38 +0300 Subject: [PATCH 12/12] Update 0000-hierarchic-anonymous-life-time.md --- text/0000-hierarchic-anonymous-life-time.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/text/0000-hierarchic-anonymous-life-time.md b/text/0000-hierarchic-anonymous-life-time.md index 9c11c5f56a2..e1d66af2cab 100644 --- a/text/0000-hierarchic-anonymous-life-time.md +++ b/text/0000-hierarchic-anonymous-life-time.md @@ -15,11 +15,11 @@ Sometimes during refactoring such code: ```rust struct City { name: String, + population: u32, } struct State { city: Vec, - covid_deaths: u32, } struct Country { @@ -31,11 +31,11 @@ developer decides to make an inner item a reference: ```rust struct City<'a> { name: &'a str, + population: u32, } struct State<'a> { city: Vec>, - covid_deaths: u32, } struct Country<'a> { @@ -48,11 +48,11 @@ What if instead of writing manually we will specify reference fields with anonym ```rust struct City& { name: &str, + population: u32, } struct State& { cities: Vec, - covid_deaths: u32, } struct Country& { @@ -65,11 +65,11 @@ Developer just could anons that this structure will use references some times wi ```rust struct City& { name: String, + population: u32, } struct State& { cities: Vec, - covid_deaths: u32, } struct Country& { @@ -81,11 +81,11 @@ Compiler underhood will generate the following code: ```rust struct City&<'anon> { // 'anon is implicitly added life-time obj: &'anon str, + population: u32, } struct State&<'anon> { // 'anon is implicitly added life-time composite_obj: Vec>, // 'anon is implicitly used here - covid_deaths: i32, } struct Country&<'anon> { // 'anon is implicitly added life-time