| Agreed. Good site. This is an aside, and I sincerely apologize for that, but I am compelled... I'm reading the greeting/hello-world example on this nice site and I notice unwrap_or(). That is a poor name: can it panic, as suggested by the "unwrap" part (I have just enough Rust to know that,) or can it not, as suggested by the "or" part? The name is inherently ambiguous! It's as if the .unwrap() that is festooned throughout such example Rust code has become so ubiquitous that someone felt it had to be used and so tacked on "_or". Why couldn't it just be .or() or perhaps .default()? And so I investigate and things go rapidly downhill from there. Consider: unwrap
unwrap_or
unwrap_or_else
unwrap_or_default
or
or_else
Good grief. The word ambiguous seems inadequate to describe what has emerged here.Again I'm sorry; this is clearly off topic, probably badly naive and possibly inappropriate in a few other ways to which I'm pathetically oblivious. I couldn't help myself. |
In this case, the "container" is option, but similar types have the same methods, like Result.
> Why couldn't it just be .or() or perhaps .default()?
or returns Option<T>, unwrap_or returns T. .default returns the default value for a T already.
TL;DR: you have a lot of options (pun intended, sorry!) with what to do, but the names all follow a quite regular scheme.