Content
@
https://www.rust-lang.org
0 reply
0 recast
0 reaction
@
0 reply
0 recast
0 reaction
franco
@francos.eth
You would need to specify a lifetime since you’re returning a borrowed reference. I don’t remember right now if you can annotate lifetimes in closures 😅 but you could do: let closure = |x: &str| x.to_owned();
1 reply
0 recast
1 reaction
@
0 reply
0 recast
0 reaction
franco
@francos.eth
Lifetime elision rules. The param s gets a lifetime because its a ref, since there is only one input lifetime it gets assigned to the output. I don’t get why the same doesn’t apply to the closure though. Maybe depends on the context of the closure and how its used 🤔
0 reply
0 recast
1 reaction