Can I create a binding with the type Option<&str>
? Tiny non-working example:
fn main() {
let a: Option<&str> = {
Some(&{"a".to_string() + "b"}) // Let's say the string is not static
};
}
This does not work, I need to add lifetime (or use a Option<String>
without &
). So how can I declare lifetime here? I know I can return a Option<String>
and everything will be fine, but that's not what I want — I'm trying to understand some Rust mechanics. I can declare lifetime in a function, but don't know how to do this in a simple let
binding.