How to convert a Vec<Vec<f64>> into a string

Viewed 972

I am new to Rust, and I am struggling with a simple task. I'd like to convert a matrix into a string, with the fields separated by tabs. I think this is possible by using the map function or something similar, but right now whatever I try gives me an error.

This is what I have, and I'd like to convert the col part into function, which returns a tab separated string, which I can print. In Python this is something like row.join("\t"). Is there something similar in Rust?

fn print_matrix(vec: &Vec<Vec<f64>>) {
    for row in vec.iter() {
        for col in row.iter() {
           print!("\t{:?}",col);
        }
        println!("\n");
    }
}
2 Answers
Related