Cannot return value referencing temporary value while lifetime should be valid

· Users Rust Lang · Aug. 29, 2026, 11:24 p.m.
Summary
The post discusses a Rust programming issue related to lifetimes and temporary values. The author attempts to create a vector of references to a string but encounters a lifetime error. They provide code examples to illustrate the problem and suggest an alternative that works, which is to return the string slice directly instead of using a struct method.
AUTHOR
Sponsored
Zulip logo Zulip
Organized team chat for people who take work seriously. Topic-based threading keeps conversations focused.
Try Zulip
Become a sponsor →