簡體   English   中英

將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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM