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.

Revisions

  1. webmaster128 revised this gist Sep 5, 2023. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions coins_iteration.rs
    Original file line number Diff line number Diff line change
    @@ -13,10 +13,11 @@ fn can_loop_through_coins() -> StdResult<()> {
    println!("Element: {owned_coin}");
    }

    // Element: 65uatom
    // Element: 130uwasm
    // Element: 65uatom
    // Element: 130uwasm

    Ok(())
    }
    }

    // Prints
    // Element: 65uatom
    // Element: 130uwasm
    // Element: 65uatom
    // Element: 130uwasm
  2. webmaster128 created this gist Sep 5, 2023.
    22 changes: 22 additions & 0 deletions coins_iteration.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #[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}");
    }

    // Element: 65uatom
    // Element: 130uwasm
    // Element: 65uatom
    // Element: 130uwasm

    Ok(())
    }