Похожие чаты

How can I convert Option<Vec<Value>> into Vec<String>? (Value from serde_json) I tried

this:
let names: Vec<String> = names.unwrap_or_else(|| Vec::<Value>::new()).iter().map(|n| n.to_string()).collect();
But something wrong with the type of the empty vector

Update:
This way it worked. but I'm still cerious why it didn't worked in the first place and if there's another simpler way
let names: Vec<String> = match names {
Some(values) => {
values
.iter()
.map(|n| n.to_string())
.collect()
},
None => Vec::new(),
};

1 ответов

18 просмотров

What is wrong with the empty vec type? the first example works just fine for me, you can also replace it with unwrap_or_default() to not get into typing at all

Похожие вопросы

Карта сайта