Is there one-line syntax for constructing a struct that contains a reference to a temporary?

后端 未结 1 1811
轮回少年
轮回少年 2021-01-24 16:27

Consider the following invalid Rust code. There is one struct Foo that contains a reference to a second struct Bar:

struct Foo<\'a&g         


        
相关标签:
1条回答
  • 2021-01-24 17:02

    No, there is no such syntax, other than what you have typed.

    For the details of how long a temporary lives when you take a reference to it, see:

    • Why is it legal to borrow a temporary?

    There will be a parent struct owning both the bar and the foos referencing it.

    Good luck:

    • Why can't I store a value and a reference to that value in the same struct?
    0 讨论(0)
提交回复
热议问题