私は言葉がマクベスに表示された回数をカウントしていますのせいに思わ「借りた値が十分に長く住んでいないが、」間違ったこと
error[E0597]: borrowed value does not live long enough
--> src/main.rs:14:9
|
11 | for w in l.unwrap().split_whitespace() {
| ---------- temporary value created here
...
14 | }
| ^temporary value dropped here while still borrowed
...
18 | }
| - temporary value needs to live until here
|
= note: consider using a `let` binding to increase its lifetime
実際の問題はw
が参考になるため、w.to_string()
に変更すると解決します。私は、問題がw
のときに、Rustコンパイラがl
に責任を指摘している理由を知りません。 w
がここで問題であると推測する方法はありますか?