missing lifetime specifier on a function returning a reference
Been writing Rust for about three months, still tripping over lifetimes. I have a helper that takes two string slices and returns the longer one. Compiler says:
error[E0106]: missing lifetime specifier
--> src/lib.rs:12:34
|
12 | fn longer(a: &str, b: &str) -> &str {
| ^ expected named lifetime parameter
|
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
I can fix it by naming a lifetime but I don't understand which one to attach. Both inputs live long enough as far as I can tell. Why can't it just figure it out?
4 replies