我很遗憾地问这么简单的问题......前一天,我开始学习Rust并尝试了这个println!方法.
fn main() {
println!("Hello {}!", "world");
}
-> Hello world!
Run Code Online (Sandbox Code Playgroud)
然后,我找到了其他格式样式:{}, {:}, {:?}, {?},...
我知道{}相反String,但我不理解其他格式风格.这些款式如何相互不同?我认为{:?}是数组或向量.这是对的吗?
请用示例代码解释这些格式样式:(
我试图将 a 的内容输出syn::Expr到控制台,但出现以下错误:
error[E0599]: no method named `to_string` found for type `&syn::Expr` in the current scope
--> derive/src/lib.rs:165:40
|
165 | println!("Expression: {:#?}", expr.to_string());
| ^^^^^^^^^
|
= note: the method `to_string` exists but the following trait bounds were not satisfied:
`syn::Expr : std::string::ToString`
`&syn::Expr : std::string::ToString`
`syn::Expr : std::string::ToString`
Run Code Online (Sandbox Code Playgroud)
我不清楚什么是“特质界限”或如何满足它们。有什么简单的方法可以输出这个变量的内容吗?
rust ×2