Skip to content

Instantly share code, notes, and snippets.

@brookback
Created May 27, 2021 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brookback/d606038a461f5628008e379c5677334f to your computer and use it in GitHub Desktop.
Save brookback/d606038a461f5628008e379c5677334f to your computer and use it in GitHub Desktop.
fn main() {
let lol: Option<&str> = Some("lol");
if lol.is_none() {
// do some error handling
return;
}
// I'd love if `lol` was asserted to be Some("lol")
// below this if clause.
assert_eq!(lol, Some("lol"));
// …buuut it's not, so I must (is this safe now?!) unwrap()
// it to work with its value.
let lel = lol.unwrap();
assert_eq!(lel, "lol");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment