Wait a minute since when?

fn i_didnt_know_this_works(opt: Option<String>) -> Option<String> {
    opt.as_ref()?;
    opt
}

I never thought I'd be so appreciative to clippy for once :joy:

1 Like

Do you have a question?

2 Likes

Since November 22, 2017.

5 Likes

Wow stable Rust is already 9 years old now. So it's been 9 years since I started working with it.
Where does the time go :thinking:

1 Like

Is the question why (Option<&String>)? works? Because only the "error" case type needs to match for ?, which is always true for Option.

The gnarly detail is in the (unstable to implement) Try trait

3 Likes

Nah no question here. It was more, it had never occurred to me that you could use ? w/ types other than Result. I had just always assumed that it was syntax sugar and so I never made the connection that it could be used w/ other types.

Excuse my ignorance, I thought "community" was for off topic stuff and when I stumbled on this it blew my mind so I just wanted to see some history behind it.

Sure, it's just that it's also cool that the "success" type doesn't have to match.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.