当我尝试使用to_string()将ethereum_types::H256
转换为String
时,出现了问题。
use ethereum_types::H256;
fn main() {
let s = H256::zero();
println!("{}", s);
}
我期望的输出结果是:
"0x0000000000000000000000000000000000000000000000000000000000000000"
但输出的结果是
"0x0000…0000"
std::string::String
没有实现std::fmt::LowerHex
特性。 - Shashi Razto_string
?请注意,我已经从你的问题中将其编辑掉了,因为使用format!
宏族列时从不需要调用to_string
。to_string
总是等效于Display
,但调用to_string
然后将结果传递给format!
宏会导致效率降低。它还会阻止你使用除Display
之外的特性。 - mcartonto_string
。我的最终目标是将s
转换为字符串并写入 .csv 文件,但是当我这样做时,它会在我的文件中写入"0x0000…0000"
。 - Shashi Razfmt
模块的文档。您不需要使用to_string
。 - mcarton