如何解决如何将十六进制字符串转换为 Vec<u8>
我想将作为外部数据获得的十六进制字符串转换为托盘中的 Vec。 出于这个原因,我尝试使用“hex::decode”,但出现以下编译错误并且无法使用它。 你能告诉我解决方法或替代方法吗?
error: duplicate lang item in crate `sp_io` (which `pallet_offchain` depends on): `panic_impl`.
|
= note: the lang item is first defined in crate `std` (which `hex` depends on)
= note: first deFinition in `std` loaded from /Users/shin.takahashi/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/wasm32-unkNown-unkNown/lib/libstd-38314f0df48bc600.rlib
= note: second deFinition in `sp_io` loaded from /Users/shin.takahashi/develop/substrate/newest_node_template/substrate-node-template/target/release/wbuild/node-template-runtime/target/wasm32-unkNown-unkNown/release/deps/libsp_io-33eeda8e29be2065.rMeta
error: duplicate lang item in crate `sp_io` (which `pallet_offchain` depends on): `oom`.
|
= note: the lang item is first defined in crate `std` (which `hex` depends on)
= note: first deFinition in `std` loaded from /Users/shin.takahashi/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/wasm32-unkNown-unkNown/lib/libstd-38314f0df48bc600.rlib
= note: second deFinition in `sp_io` loaded from /Users/shin.takahashi/develop/substrate/newest_node_template/substrate-node-template/target/release/wbuild/node-template-runtime/target/wasm32-unkNown-unkNown/release/deps/libsp_io-33eeda8e29be2065.rMeta
error: aborting due to 2 prevIoUs errors; 6 warnings emitted
我的代码如下。
fn get_decoded_address(address:&str)-> Vec<u8> {
//value of address is like following. "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"
hex::decode(&address).unwrap()
}
解决方法
我必须正确地写“Cargo.toml”。以下是示例。
rustc-hex = { version="2.1.0",default-features = false }
[features]
default = ['std']
std = [
'rustc-hex/std',]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。