这是我的代码:
fn fetch_transaction (graph: &mut Vec<(&'static str, Transaction)>, tx_id: &'static str) -> Transaction {
for item in graph.iter() {
if item.0 == tx_id {
return item.1;
} else {
println!("Transaction not found.");
}
}
}
顺便说一下,物品.1是事务 struct 类型,而item.0是静态字符串.当我编译它时,会出现以下错误:
fn fetch_transaction (graph: &mut Vec<(&'static str, Transaction)>, tx_id: &'static str) -> Transaction {
| ----------- expected `Transaction` because of return type
54 | / for item in graph.iter() {
55 | | if item.0 == tx_id {
56 | | return item.1;
57 | | } else {
58 | | println!("Transaction not found.");
59 | | }
60 | | }
| |_____^ expected struct `Transaction`, found `()`
为什么会这样,我如何修复它.