#lazy-evaluation #join #iterator #format #human

join-lazy-fmt

Lazy separator.join(iterable) method and lazy_format! for Rust

3 releases

0.9.2 Mar 20, 2019
0.9.1 Mar 20, 2019
0.9.0 Mar 20, 2019

#2710 in Rust patterns

Download history 8602/week @ 2023-12-06 8436/week @ 2023-12-13 3700/week @ 2023-12-20 2475/week @ 2023-12-27 5399/week @ 2024-01-03 6770/week @ 2024-01-10 11162/week @ 2024-01-17 9787/week @ 2024-01-24 5637/week @ 2024-01-31 6064/week @ 2024-02-07 8036/week @ 2024-02-14 9749/week @ 2024-02-21 7039/week @ 2024-02-28 9291/week @ 2024-03-06 10693/week @ 2024-03-13 7483/week @ 2024-03-20

35,990 downloads per month
Used in 6 crates (3 directly)

MIT license

10KB
102 lines

join-lazy-fmt

Lazy separator.join(iterable) method and lazy_format! for Rust

Repository Latest version Documentation License

Usage

  1. Add the following line to your Cargo.toml, under [dependencies]

    join-lazy-fmt = "0.9.2"
    
  2. Add the folowing line to your .rs code to bring items in scope:

    use ::join_lazy_fmt::*;
    

Example

use ::join_lazy_fmt::*;

let sequence = format!("[{}]", ", ".join(0 .. 5));
assert_eq!(sequence, "[0, 1, 2, 3, 4]");

// Since `.join()` is lazy, this does not compute an infinite string.
let _ = ", ".join(0 ..);

const N: usize = 6;
let line = format!("+-{}-+", "-+-".join((1 .. N).map(|_| "---")));
// And the following allocates only one `String`:
let matrix = format!(
    "{line}\n{body}\n{line}\n",
    line=line,
    body="\n".join(
        (1 .. N).map(|i| lazy_format!(
            "| {row} |",
            row=" | ".join(
                (1 .. N).map(|j| lazy_format!(
                    "a{i}{j}",
                    i=i,
                    j=j,
                ))
            ),
        ))
    ),
);
assert_eq!(matrix, "\
+-----+-----+-----+-----+-----+
| a11 | a12 | a13 | a14 | a15 |
| a21 | a22 | a23 | a24 | a25 |
| a31 | a32 | a33 | a34 | a35 |
| a41 | a42 | a43 | a44 | a45 |
| a51 | a52 | a53 | a54 | a55 |
+-----+-----+-----+-----+-----+
");

No runtime deps

Features