Crate of the Week

I recently learned about bit-parallel glushkov NFA evaluation for regex and it's pretty cool stuff. :slight_smile:

I'd like to nominate literator for crate of the week. A crate for Displaying iterator of things.

In my Rust career, I wrote a lot of custom Display just so I could print out contents of a list with a nice comma-delimited format.

I just found this crate while thinking "but someone has to have written a crate for that already" and searching on lib.rs. And it turns out it does! This crate encapsulates all that mess, and I I'll never have to write the following ever again :sweat_smile: :

        if let Some(first) = iter.next() {
            write!(f, "{first}")?;
        }
        let but_last = iter.len().saturating_sub(1);
        for elem in iter.by_ref().take(but_last) {
            write!(f, ", {elem}")?;
        }
        if let Some(last) = iter.next() {
            write!(f, ", and {last}")?;
        }

I can now just do:

        write!(f, "{}", iter.join_comma_and())

I nominate postcard: "Postcard is a #![no_std] focused serializer and deserializer for Serde."

Although it says it is "primarily for #![no_std] usage", I have found it good for my general serialisation needs.

FWIW, there's Itertools::format for basic delimited output, and format_with can do a bit more, but probably still not everything that literator provides.

Wanna self-nominate komadori (not to mistake with komadori-rayon I previously posted here)

komadori is a crate that helps you write reductions declaratively, especially in cases like you want to do more than one reduction in one traversal pass, such as calculating sum and max, or calculating max and collecting to Vec together.

Btw I spent time on the version 0.8.0 optimizing Vec reduction so that this:

let nums = [1, 2, 3];

let (sum, doubles) = nums
    .into_iter()
    .feed_into((
        0.into_sum(),
        vec![].into_collector().map(|num| num * 2),
    ));

can be lowered into a nice vectorized one-pass loop (on my ARM64 machine)

LBB272_29:
        ldp q4, q5, [x10, #-32]
        ldp q6, q7, [x10], #64
        add.4s v1, v4, v1
        add.4s v0, v5, v0
        add.4s v2, v6, v2
        add.4s v3, v7, v3
        add.4s v4, v4, v4
        add.4s v5, v5, v5
        add.4s v6, v6, v6
        add.4s v7, v7, v7
        stp q4, q5, [x11, #-32]
        stp q6, q7, [x11], #64
        subs x16, x16, #16
        b.ne LBB272_29

and very performant compared to most approaches.

One of the obvious approaches that look equivalent is this, which unfortunately doesn’t get vectorized (hence much slower) for some reason (this is what old komadori is conceptually lowered to):

let nums = [1, 2, 3];

let mut sum = 0;
let mut doubles = Vec::with_capacity(nums.len());
for num in nums {
    sum += num;
    // LLVM still inserts capacity check (we did reserve) :(
    doubles.push(num * 2);
}

I would like to self nominate avrogen a tool to generate rust structures from apache avro files.
Used in build.rs the code remains synchronized with modifications done in .avsc files.

I'd like to self-nominate docling, a Rust port of the Docling document converter that is officially part of Docling Project. It reads PDF, DOCX, PPTX, XLSX, HTML, EPUB, ODF, RTF and a couple dozen other formats into a single DoclingDocument structure and serializes it to Markdown or JSON. The declarative backends also build for wasm32-unknown-unknown, so the same converter runs in a browser.

I would like to self-nominate my UML diagram generation tool auto-uml for the crate of the week. It hijacks tree-sitter to deterministically create UML diagrams for codebases extremely quickly (It can do the entirety of chromium in ~40.2 seconds). I've been building it out for a couple months now. It has support for a few languages and I finally feel like it's in a good enough state for wider use. I've gotten great feedback for it, I just want to bring it to more users.