DEV Community

Gabor Szabo
Gabor Szabo

Posted on • Originally published at rust.code-maven.com

2

Rust Source Code Reading: The thousands crate

Yesterday I had the first live code-reading event. I attempted to understand how the "thousands" crate works. 🦀 It can commafy a number converting a number such as 1234567 into a string like this "1,234,567" to make it more readable.

This is part of the Rust Maven live events series. During this event went over the implementation of this crate.

A couple of observations, and let me emphasize, this is not a (negative) critique of the crate or the author.

🦀 If there are tests, starting from them can help understanding the flow of the code. Unfortunately in some cases the tests themselves are a bit too complex. (This was not such case.)

🦀 If there is a nice and simple example of how to use the crate, we can start from that code trying to explore the implementation.

🦀 We could observe (or rather guess) the evolution of the crate from specific solution (dealing with digits) to more generic solution (dealing with any set of characters). Some variable/function/etc. names were using the generic vocabulary, some other were still in the original way talking about digits.

🦀 There are multiple ways to define type-constraints (e.g. immediately after the type-name or in a "where"-clause. Mixing them can confuse Gabor. (Maybe others as well. )

🦀 The audience in such code-reading can help.

🦀 One hour was not enough even for such small crate and even after I already invested some time trying to understand it.


🦀 Watch the recordings here

🦀 If you are interested in earlier (and future) live events check them out here.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up