can you explain the joke, i work at cloudflare
Rust has many container-like objects that may or may contain a value, like Box. Most of these have an unwrap() method that either obtains the inner value or panics the whole application.
Box is a bad example; it always has a value and can’t be unwrapped. It’s Result<T> and Option<T> that are the primary wrappers.
Result is for Errors, and Option is for nullables. If you consider it that way, the “issues” with unwrap are identical to other languages when errors and nulls aren’t properly handled.
Whoosh
I reckon the person you’re replying to knows exactly what unwrap is, because the last big famous Cloudflare outage was caused by it. They were making a joke of their own
sounds like an error handling issue
Yes it is. Typically you’d do some pattern matching to handle every possible case, but Unwrap is often used as a shortcut.
Is this just like the equivalent of a getter method in C++?
It’s worse than just exceptions in C++. There’s (almost) no way for the caller of your function to catch it. It’s a bit like this snippet:
std::optional<int> foo = <...>; try { return foo.value(); } catch(const std::bad_optional_access& e) { std::cout << e.what() << std::endl; abort(); }It’s the
abortthat is the crux of the issue here. Usually you would pass thestd::optionalup/down the call stack. If you don’t control the types (e.g. using a library or a framework) you’d come up with some “default” value instead, like this:std::optional<int> foo = <...>; return foo.value_or(123);Or in Rust:
let foo : Option<i32> = <...>; return foo.unwrap_or(123);But sometimes there’s no good “default” value, and then you have to resort to just
unwrap-ing the value, and accepting that the entire program will abort when that function call fails. Usually this is a sign of poor engineering somewhere, likely in a library you’re using, and should be fixed; but sometimes you don’t have the time to fix it, and then it ends up in production.It’s more like a method that can throw an exception. Rust doesn’t really have exceptions, but if you have a Result<T> or Option<T> type you can Unwrap it to get just the T. But if there’s no T to get (in the case of an Error type for Result for None for Option) the call panics.
i work at cloudflare
Thank you for the easier captchas, and pre-emptively damn you for whatever evil thing CloudFlare will eventually do with their MITM access to everything.
i work at cloudflare
I shouldn’t worry about it.
.unwrap_or_ruin_christmas()




