fn func<'a, T>(arg: Vec<Box<T>>)
where
String: From<&'a T>,
T: 'a,
{
let s: Vec<String> = arg.iter().map(|s| String::from(s)).collect();
do_something_else(arg);
}
fn do_something_else<T>(arg: Vec<Box<T>>) {}
Компилятор жалуется, что arg
не живет достаточно долго.Почему, хотя?
error[E0597]: `arg` does not live long enough
--> src/lib.rs:6:26
|
6 | let s: Vec<String> = arg.iter().map(|s| String::from(s)).collect();
| ^^^ borrowed value does not live long enough
7 | do_something_else(arg);
8 | }
| - borrowed value only lives until here
|
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 1:9...
--> src/lib.rs:1:9
|
1 | fn func<'a, T>(arg: Vec<Box<T>>)
| ^^