I think unwrap is indeed not a straightforward name. When I was a newbie at Rust, I thought to get the value I use .unwrap() because the tutorial I followed was also using unwrap, so this is indeed a footgun. I only understood it would panic after I once got a panic crash from unwrap, then I started to search deeper about unwrap and realized that it would panic if there is an error
But if it is named or_panic(), like
insert_data(data).or_panic()
The name is straightforward, just from reading the syntax, the user could already understand that it would insert a data or panic. Easy beginner experience, easy code screening, lower cognitive load
Expect is also not a straightforward name. When I was a beginner at Rust, I was also confused about expect, I thought the code would expect this value, but it turns out that it is for panicking the app with a custom message
It is easier like this:
get_data().or_panic()
get_data().or_panic_with("no data available")
The user instantly understands it would get the data or panic, and get the data or panic with this message
The tutorial would follow, we just need to update the official tutorial, the 3rd party tutorial would adapt, just like when Rust does breaking changes between editions
After the user reads the name syntax .or_panic() and .or_panic_with(), he then faster understands they would do the intended operation or panic
Could it be automated with a tool like a find-and-replace button in a code editor?
I have written a transpiler that replaces Javascript syntax to Rust syntax, so we could just write an automation tool that would replace the unwrap word to or_panic, and expect to or_panic_with