【发布时间】:2021-11-14 03:15:57
【问题描述】:
我正在尝试通过使用 for 循环的 API 创建的此变量的结果进行迭代(此处已注释,否则会出错):
let create_account_instruction: Instruction = solana_sdk::system_instruction::create_account(
&wallet_pubkey,
&mint_account_pubkey,
minimum_balance_for_rent_exemption,
Mint::LEN as u64,
&spl_token::id(),
);
println!("Creating the following instructions: {:?}", create_account_instruction);
// for x in create_account_instruction {
// println!("{:?}", x)
// }
这是我想要迭代的结果(仅供参考:那些私钥和公钥仅用于在 devnet 上进行测试):
Creating the following instructions: Instruction { program_id: 11111111111111111111111111111111, accounts: [AccountMeta { pubkey: ESCkgk5AfDC8cXd4KYjkUda1psCL8otfu8NvniUBiGhX, is_signer: true, is_writable: true }, AccountMeta { pubkey: Ah63GoKnnBicTELvfz2F9YvF9vaR51HR2BK3hJWwWE8x, is_signer: true, is_writable: true }], data: [0, 0, 0, 0, 96, 77, 22, 0, 0, 0, 0, 0, 82, 0, 0, 0, 0, 0, 0, 0, 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235, 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133, 126, 255, 0, 169] }
如果我尝试通过 for 循环遍历它(取消注释上述内容),我会收到此错误:
Compiling AmatoRaptor v0.1.0 (/home/joomjoo/Desktop/Tester)
error[E0277]: `Instruction` is not an iterator
--> src/main.rs:89:14
|
89 | for x in create_account_instruction {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `Instruction` is not an iterator
|
= help: the trait `Iterator` is not implemented for `Instruction`
= note: required because of the requirements on the impl of `IntoIterator` for `Instruction`
note: required by `into_iter`
--> /home/joomjoo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/collect.rs:234:5
|
234 | fn into_iter(self) -> Self::IntoIter;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain
我的问题是迭代结果的最简单方法是什么?
【问题讨论】:
-
什么是“结果”?
标签: for-loop rust iterator rust-cargo