简体   繁体   中英

How Rust turn Vec<Vec<char>> to Vec<String>?

For a example:

let record: Vec<Vec<char>> = vec![vec!['.'; 10]; 10];
let example: Vec<String> = record.into_iter().into_iter().collect::<String>().collect::<Vec<String>>();

this doesn't work. how to trans record to example.

You need to iterate and collect each of them to a String :

let example: Vec<String> = record
    .iter()
    .map(|v| v.iter().collect::<String>())
    .collect();

Playground

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM