list_builder 0.0.2

Python-like list comprehensions in Rust
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented0 out of 0 items with examples
  • Size
  • Source code size: 5.96 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.08 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Documentation
  • lily-mara/rust-list-builder
    3 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • lily-mara

Rust List Builder

List/set/generator comprehensions are one of the best features of Python and Haskell. They make creating complex iterables simpler and more intuitive. This crate attempts to add similar functionality to the Rust language.

This crate provides the gen! macro. Its syntax is similar to Python list comprehensions:

#[macro_use(gen)]
#[no_link]
extern crate list_builder;

fn main() {
	let x: Vec<i32> = gen![i*1000 => i in [1, 2, 3, 4, 5, 6]];
}

You can use conditionals just like in Python:

let x: Vec<i32> = gen![i*1000 => i in [1, 2, 3, 4, 5, 6], i % 2 == 0];
assert_eq!(x, vec![2000, 4000, 6000]);