【发布时间】:2020-07-19 03:07:59
【问题描述】:
我正在使用只接受字符串文字的宏 hex!。
我有一个从函数返回并存储在变量中的值。我无法对这些值进行硬编码并调用此函数。那么,如何使用变量调用hex! 宏呢?
这是我的工作代码:
let account: AccountId32 = hex_literal::hex!["d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"].into();
这是我遇到错误的代码:
let account_id = "d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d";
let account: AccountId32 = hex_literal::hex!(&account_id).into();
错误是:
error: proc-macro derive panicked
--> src/examples/example_substratekitties.rs:49:32
|
49 | let account: AccountId32 = hex_literal::hex!(&account_id).into();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: message: expected one string literal
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
hex! 宏的所有示例仅使用字符串文字进行演示。
【问题讨论】:
-
我不确定
&在这里是否必要。 -
删除了,还是一样的错误。
-
您要解决什么问题?将十六进制字符串转换为数字运行时?
标签: rust