When I have wrapped data like Some(Some(val)) how can I safely unwrap the value?
I thought about using match and if let but both ends up being redundant, and unwrap() can cause panic.
What is the best way to unwrap wrapped data concisely (ideally online like JS optional chaining) and safely?
use std::collections::HashMap;
fn main() {
let a = Some(Some(Some(Some(HashMap::from([(
"test".to_owned(),
Some("test".to_owned()),
)])))));
// Very redundant
if let Some(a) = a {
if let Some(a) = a {
if let Some(a) = a {
if let Some(a) = a {
let val = a["test"].clone();
if let Some(_val) = val {
// something with val
todo!();
}
}
}
}
}
}