Ever got frustrated when you realize that the for loop you were writing

Overview

for_each_repeat

Ever got frustrated when you realize that the for loop you were writing...

fn foo(mut iter: impl Iterator
   i32>) {
    
   for i 
   in iter {
        
   // do something...
        
   if i 
   == 
   42 {
            
   // ughh
        }
    }
}
  

...needs to repeat the current iteration in some cases?
You may though: "Oh come on now I need to think on how to rewrite this into a while loop!"

Fear not! Cause we've got

Repeat

Import for_each_repeat::ForEachRepeat and put your for loop's body into a closure, that has to return LoopControl type. Using Repeat you are able to redo current iteration with the same iterator value.

use for_each_repeat::{ForEachRepeat, LoopControl};

fn foo(mut iter: impl Iterator
   i32>) {
    
   let _: 
   Option
   <()
   > 
   = iter.
   for_each_repeat(
   |i
   | {
        
   // do something...
        
   if i 
   == 
   42 {
            
   // process it...
            
   return LoopControl
   ::
   Repeat(i);
        }
        LoopControl
   ::
   Continue(())
    });
}
  

#![no_std]

This crate can be used in no_std environment.

You might also like...
osu-link is a program which links osu!stable beatmaps to osu!lazer's new store format, saving you disk space.

osu-link is a program which links osu!stable beatmaps to osu!lazer's new store format, saving you disk space.

Modrinth API is a simple library for using, you guessed it, the Modrinth API in Rust projects

Modrinth API is a simple library for using, you guessed it, the Modrinth API in Rust projects. It uses reqwest as its HTTP(S) client and deserialises responses to typed structs using serde.

Keep distractive apps at bay allowing you to focus!
Keep distractive apps at bay allowing you to focus!

Focus Keep distractive apps at bay allowing you to focus! What it does. The apps specified are killed automatically after a period of 5 seconds till t

A discord bot that safely executes whatever rust you throw at it. Remote code execution as a service
A discord bot that safely executes whatever rust you throw at it. Remote code execution as a service

RustBot Bot is still under development and not ready for production use RustBot is a discord bot that executes whatever rust code you throw at it. In

Gnu-copypasta-maker - You'd just wanna interject for a moment!

GNU Copypasta Maker To compile, use make. To install, use sudo make install or if you are root make install To uninstall, use sudo make uninstall or i

Minimalistic solana minter program if you don't want to use Metaplex

Minimalistic solana minter program The objective of this repository is to be only a minimalistic template for NFTs projects on Solana, so you can buil

Telegram bot help you to run Rust code in Telegram via Rust playground
Telegram bot help you to run Rust code in Telegram via Rust playground

RPG_BOT (Rust Playground Bot) Telegram bot help you to run Rust code in Telegram via Rust playground Bot interface The bot supports 3 straightforward

Examples from the talk Why you should learn Rust

Why you should learn Rust: Examples This repository contains the examples from the talk "Why you should learn Rust". All examples demonstrate that the

Simple programming language that speaks the ones you already know!

Simple programming language that speaks the ones you already know!

Owner
null
A metamacro toolkit for writing complex macros.

Big Mac This crate contains the branching_parser! metamacro, which can be used to create complex macros with few lines of code. To use the macro, call

null 1 Nov 14, 2021
Rust SDK for writing contracts for Stellar Jump Cannon

rs-stellar-contract-sdk Rust SDK for writing contracts for Stellar Jump Cannon. This repository contains code that is in early development, incomplete

Stellar 44 Dec 28, 2022
Macros to make writing proc-macro crates easy

proc-easy Macros to make writing proc-macro crates easy. This crate provides mainly macros and supporting types and traits to reduce amount of boilerp

Zakarum 7 Jan 1, 2023
This crate provides a convenient macro that allows you to generate type wrappers that promise to always uphold arbitrary invariants that you specified.

prae This crate provides a convenient macro that allows you to generate type wrappers that promise to always uphold arbitrary invariants that you spec

null 96 Dec 4, 2022
The batteries for core that you never knew you needed.

core+ The batteries for core that you never knew you needed: core+ coreplus documentation Core+ contains types that make it possible to write no_std l

Lachlan Sneff 12 May 11, 2022
Tells you how many years you need to wait until your subatomic xeon crystal synchronizer has doubled in plasma inversion efficiency on the Goldberg-Moleman scale or whatever.

about Tells you how many years you need to wait until your subatomic xeon crystal synchronizer has doubled in plasma inversion efficiency on the Goldb

null 2 Dec 3, 2021
A tool that, like, screams at you when you say like

Dislike Do you, like,... dislike constantly saying "like" as much as I do? Then, like,... you've come the right place! This tool is like EXACTLY what

ElKowar 27 Jun 27, 2022
Rust library that can be reset if you think it's slow

GoodbyeKT Rust library that can be reset if you think it's slow

null 39 Jun 16, 2022
The nightly_crimes!{} macro commits horrible crimes to allow you to enable nightly features on the stable compiler.

The nightly_crimes!{} macro commits horrible crimes to allow you to enable nightly features on the stable compiler.

Mara Bos 151 Dec 16, 2022
Achieve it! How you ask? Well, it's pretty simple; just use greatness!

Greatness! Achieve it! How you ask? Well, it's pretty simple; just use greatness! Disclaimer I do not believe that greatness is the best. It fits a me

Isacc Barker (Milo Banks) 107 Sep 28, 2022