"特质绑定std :: fmt :: Display不满意"是什么意思?

Дми*_*мар 6 rust

我的代码:

extern crate time;

fn main() {
    println!("{}", time::get_time());
}
Run Code Online (Sandbox Code Playgroud)

我的错误是:

Error 'the trait bound time::Timespec: std::fmt::Display is not satisfied

mal*_*rbo 19

println!是一个做格式化输出的宏.{}用于打印实现Display特征的值.错误是说Timespec没有实现Display特性,所以它不能用于{}.

你可以用{:?}而不是{}.{:?}用于打印实现Debug特征并Timespec实现特征的值.

考虑阅读fmt模块文档,它会详细解释.

  • @ДмитрийКомар也尝试读取整个编译器错误.这不仅仅是噪音,它通常实际上很有用:```note:`time :: Timespec`不能用默认的格式化程序格式化; 如果你使用格式字符串```,请尝试使用`:?` (2认同)