block_effects

Crates.ioblock_effects
lib.rsblock_effects
version0.1.1
sourcesrc
created_at2020-09-08 09:29:14.75197
updated_at2020-09-08 09:39:47.281145
descriptionA macro to chain block effects
homepage
repositoryhttps://github.com/TheNappap/block_effects
max_upload_size
id286084
size7,979
(TheNappap)

documentation

README

block_effects

Rust proc macro for chaining block effects.

With block_effects, it is possible to chain different block effects with the use of the block! macro.

This idea was proposed by mcy.

The block! macro is used to mark blocks with chained block effects.

The following block effects can be chained: unsafe, async, if, match, loop, while and for. Additionally if let and while let are also possible.

Goal

The main purpose of this crate is to minimize indentation for nested blocks. Unfortunately proc macros also add indentation. So to fully benefit from this one should not indent the block! macro or even put the macro braces on the same line as the block.

Example

use block_effects::block;

block!{
if let Some(_) = Some(0) if let Some(_) = Some(0) {
    assert!(true); 
}
}

let _future = block!{ unsafe async for i in 0..3 match i { 
    0..=2 => assert!(true),
    _ => assert!(false)
} };
Commit count: 17

cargo fmt