Skip to content

Instantly share code, notes, and snippets.

@webmaster128
Last active September 5, 2023 07:14
Show Gist options
  • Save webmaster128/57f32f48a98f999318704cd6044dddc9 to your computer and use it in GitHub Desktop.
Save webmaster128/57f32f48a98f999318704cd6044dddc9 to your computer and use it in GitHub Desktop.
Example for iterating Coins
#[test]
fn can_loop_through_coins() -> StdResult<()> {
let mut coins = Coins::default();
coins.add(Coin::new(123, "uwasm"))?;
coins.add(Coin::new(7, "uwasm"))?;
coins.add(Coin::new(65, "uatom"))?;
for borrowed_coin in coins.iter() {
println!("Element: {borrowed_coin}");
}
for owned_coin in coins {
println!("Element: {owned_coin}");
}
Ok(())
}
// Prints
// Element: 65uatom
// Element: 130uwasm
// Element: 65uatom
// Element: 130uwasm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment