|
|
|
|
|
by steveklabnik
2948 days ago
|
|
"unwrap" doesn't mean "panic". It means "to take out of some kind of container". So, the question is, what to do if the thing isn't in the container? unwrap: panic
unwrap_or: produce this value instead
unwrap_or_else: produce a value by running this closure instead
unwrap_or_default: produce a default value instead
or and or_else are just like unwrap_or and unwrap_or_else, but they don't do the unwrapping; you keep the container.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. |
|