将我的代码更新为新的 nightlies,他们似乎已经摆脱了 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);
}
关于string - 将 Vec 打印为字符串的惯用方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27931605/