A Rust macro for writing nested loop expressions

Overview

loop_chain

A Rust macro for writing nested loop expressions

github workflow status crates docs

Usage | Examples | Docs

Dependencies

[dependencies]
loop_chain = "0.1.1"

Usage

For expression

fn main() {
    loop_chain::loop_chain! {
        for width in 0..10;
        for height in 0..10;
        then {
            println!("width: {}, height: {}", width, height);
        }
    }
}

the generated code will be the following:

fn main() {
    for width in 0..10 {
        for height in 0..10 {
            println!("width: {}, height: {}", width, height);
        }
    }
}

While expression

fn main() {
    let mut foo = 0;
    loop_chain::loop_chain! {
        while foo < 3;
        foo += 1;
        for x in 0..10;
        then {
            println!("foo: {}, x: {}", foo, x);
        }
    }
}

the generated code will be the following:

fn main() {
    let mut foo = 0;
    while foo < 3 {
        foo += 1;
        for x in 0..10 {
            println!("foo: {}, x: {}", foo, x);
        }
    }
}

While let expression

fn main() {
    let mut foo = (0..10).collect::<Vec<u8>>();
    loop_chain::loop_chain! {
        while let Some(v) = foo.pop();
        for x in 0..10;
        then {
            println!("v: {}, x: {}", v, x);
        }
    }
}

the generated code will be the following:

fn main() {
    let mut foo = (0..10).collect::<Vec<u8>>();
    while let Some(v) = foo.pop() {
        for x in 0..10 {
            println!("v: {}, x: {}", v, x);
        }
    }
}

Loop expression

fn main() {
    let mut foo = 0;
    loop_chain::loop_chain! {
        loop;
        foo += 1;
        if foo > 3 {
            break
        };
        for x in 0..10;
        then {
            println!("foo: {}, x: {}", foo, x);
        }
    }
}

the generated code will be the following:

fn main() {
    let mut foo = 0;
    loop {
        foo += 1;
        if foo > 3 {
            break
        };
        for x in 0..10 {
            println!("foo: {}, x: {}", foo, x);
        }
    }
}

Reference

You might also like...
Thread-safe clone-on-write container for fast concurrent writing and reading.

sync_cow Thread-safe clone-on-write container for fast concurrent writing and reading. SyncCow is a container for concurrent writing and reading of da

Macro assembler for Rust

Macro Assembler This crate implement JSC/SpiderMonkey like macro assembler. Macro assembler purpose is to generate machine code for different platform

A Rust attribute macro that adds memoization to a function (rhymes with Mickey)

michie (sounds like Mickey) — an attribute macro that adds memoization to a function. Table of contents Features Non-features key_expr key_type store_

Library and proc macro to analyze memory usage of data structures in rust.
Library and proc macro to analyze memory usage of data structures in rust.

Allocative: memory profiler for Rust This crate implements a lightweight memory profiler which allows object traversal and memory size introspection.

Simple Rust derive-macro that simplifies integral enum creation

Integral enum A simple way to define integer-like enums. This macro implements bunch of traits that are usually implemented via looooong derive(..) at

A procedural macro for configuring constant values across crates

toml-cfg Rough ideas: Crates can declare variables that can be overridden Anything const, e.g. usize, strings, etc. (Only) The "root crate" can overri

Proc macro implementation of #[naked]

#[naked] Documentation This crate provide a proc macro version of the #[naked] attribute which can be used on stable Rust. Example // The SYSV64 calli

Macro for fast implementing serialize methods in serde::Serializer trait

impl_serialize! This library provides a simple procedural macro for fast implementing serialize methods in serde::Serializer trait. [dependencies] imp

hashmap macro for creating hashmap from provided key/value pairs

HashMap Macro Creates a HashMap from provided key/value pairs. Usage use std::collections::HashMap; use hashmap_macro::hashmap; let m: HashMap&str,

Releases(v0.1.1)
Owner
Takayuki Maeda
Software Engineer?
Takayuki Maeda
Representing Wolfram Language expressions in Rust.

wolfram-expr Representation of Wolfram Language expressions. Examples Construct the expression {1, 2, 3}: use wolfram_expr::{Expr, Symbol}; let expr

Wolfram Research, Inc. 7 Aug 18, 2022
:crab: Small exercises to get you used to reading and writing Rust code!

rustlings ?? ❤️ Greetings and welcome to rustlings. This project contains small exercises to get you used to reading and writing Rust code. This inclu

The Rust Programming Language 33.1k Jan 2, 2023
Take your first step in writing a compiler. Implemented in Rust.

first-step-rust Take your first step in writing a compiler, using Rust. Building from Source Make sure the Rust toolchain is installed on your compute

PKU Compiler Course 13 Aug 28, 2022
S-expression parsing and writing in Rust

rsexp S-expression parsing and writing in Rust using nom parser combinators. This implemantion aims at being compatible with OCaml's sexplib. The main

Laurent Mazare 12 Oct 18, 2022
Writing Interpreters in Rust: a Guide

Writing Interpreters in Rust: a Guide This is an online book covering the lower level topics involved in writing an interpreter in Rust including: mem

Languages Hosted in Rust Working Groups 254 Jan 5, 2023
Learn Rust by writing Entirely Too Many linked lists

Learn Rust by writing Entirely Too Many Linked Lists Read the pretty version at https://rust-unofficial.github.io/too-many-lists/. Building Building r

null 2.4k Jan 3, 2023
This project contains small exercises to get you used to reading and writing Rust code

rustlings ?? ❤️ Greetings and welcome to rustlings. This project contains small exercises to get you used to reading and writing Rust code. This inclu

Cynthia Tran 1 May 24, 2022
🕶 Assorted checks and validations for writing safer Solana programs.

vipers ?? Assorted checks and validations for writing safer Solana programs. Motivation Solana's fee mechanism is unlike Ethereum's, in that the numbe

Saber 131 Sep 14, 2022
A webring of people who make cool stuff. technology, music, art, writing, anything goes!

a webring of people who make cool stuff. technology, music, art, writing, anything goes!

Kognise 44 Dec 6, 2022
A language for writing swim practices.

swimscript A language for writing swim practices. Table of contents Purpose Language Spec Purpose The goal of swimscript is to create a universal lang

Aiden Petersen 1 Jan 30, 2022