Created
February 24, 2020 04:21
-
-
Save kuy/e9ecb9ccea50f807be2bf4a8c327544f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let selected = match props.selected { | |
Some(selected) => match serde_json::from_str::<Vec<ColorName>>(selected.as_str()) { | |
Ok(selected) => selected.into_iter().map(|cn| cn.id.to_string()).collect(), | |
_ => vec![], | |
}, | |
_ => vec![], | |
}; | |
let selected = props.selected.map_or(vec![], |s| { | |
serde_json::from_str::<Vec<ColorName>>(s.as_str()).map_or(vec![], |s| { | |
s.into_iter().map(|cn| cn.id.to_string()).collect() | |
}) | |
}); | |
let selected = props | |
.selected | |
.map_or(Ok(vec![]), |s| { | |
serde_json::from_str::<Vec<ColorName>>(s.as_str()) | |
}) | |
.unwrap_or(vec![]) | |
.iter() | |
.map(|cn| cn.id.to_string()) | |
.collect(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment