将 Vec 打印为字符串的惯用方法是什么?

What is the idiomatic way to print a Vec as a string?

正在将我的代码更新到新的晚间节目,他们似乎已经摆脱了 std::Vec

的 to_string()
src/rust_mnemonic.rs:100:39: 100:50 error: type `collections::vec::Vec<&str>` does not implement any method in scope named `to_string`
rc/rust_mnemonic.rs:100     println!("mnemonic: {}", mnemonic.to_string());

您可以使用 :? 说明符,它使用 Debug 特征。

fn main() {
    let v = vec![0u8, 1, 2, 3, 4, 5];
    println!("{:?}", v);
}

如果你想要它作为 String,那么你可以使用 format!:

fn main() {
    let v = vec![0u8, 1, 2, 3, 4, 5];
    let s = format!("{:?}", v);
    println!("-->{}<--", s);
}