'Why can I call multiple Option methods that consume self without error?
let option: Option<&str> = None;
// -- unwrap --
let unwrap = panic::catch_unwind(|| option.unwrap());
assert!(unwrap.is_err());
let unwrap_or_default = option.unwrap_or_default();
assert!(unwrap_or_default == "");
let unwrap_or = option.unwrap_or("👌");
assert!(unwrap_or == "👌");
let unwrap_or_else = option.unwrap_or_else(|| "🙌");
assert!(unwrap_or_else == "🙌");
The methods Option::unwrap_xxx(self) -> T all consume self, so why we can repeatedly call these methods without a compilation error? Isn't the Option moved?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
