Diesel Just Got Supercharged 🦀

Today’s Issue: A Terminal API Client written in Rust, Blazing Fast Ethereum Full Node (in Rust!), and Moving Beyond Type Systems

Rustaceans Editors
Rustaceans
5 min readJun 10, 2024

--

Ferris the crab mascot — Image courtesy of tweedegolf

Hello Rustacean!

Welcome to another edition of the Rust Bytes newsletter. In this issue, we’ll discuss Diesel’s latest v2.2 release, present a Rust challenge, spotlight an amazing Rust project, and highlight some incredible links of the week.

Welcome to issue 32.

THE MAIN THING

Diesel Just Got Supercharged 🦀

Diesel just hit 2.2, and let me tell you, it’s been a wild ride! Over a year, 42 awesome contributors wrangled over 560 commits, and here’s the down-low on the coolest new features:

1. Automatic Return Types? Yes Please

Remember those complex, nested query return types that made your code look like a jungle gym? Diesel v2.2 has a magic trick for that. Introducing the #[diesel::dsl::auto_type] magic dust. Just sprinkle it on your query functions, and poof! It figures out the right return type for you. No more wrestling with cryptic code – just write beautiful queries and let Diesel do the rest.

2. Debugging Your Database Like a Boss

Ever wondered what your database connection is up to? Now you can be its nosy neighbor. Diesel will now let you set up custom logging and performance measurements for your connections. Want to see exactly what queries are taking forever? Boom, you got it. Need to track down some mysterious database gremlins? Diesel’s got your back.

3. Moving Mountains of Data (the Efficient Way)

Sometimes you gotta shove a whole bunch of data into your database. In the past, this could be a real pain. But fear not, this release brings support for PostgreSQL’s COPY FROM and COPY TO commands. Think of it as a magical data pipe – just point it at your Diesel models and watch the data flow in or out with blazing speed.

4. Easier Setup, Happier You

Setting up Diesel can sometimes feel like building a spaceship. Not anymore! Diesel v2.2 now lets you bundle all the necessary drivers right into your project. This means smoother installation and even lets you build static binaries for the diesel-cli tool. Basically, getting started with Diesel just got way easier.

5. Error Messages That Don’t Suck

Ever gotten a cryptic error message from Diesel that left you scratching your head? We’ve all been there. But Diesel team is working hard to change that. They teamed up with the Rust team to make error messages clearer and more helpful. Now, they’ll often include hints on how to fix the problem, saving you time and frustration.

This release wouldn’t have been possible without the amazing contributors. A huge shoutout to everyone who contributed with code, bug reports, discussions, and moral support. You guys rock!

Share

CHALLENGE: RUST QUIZ❓

What is the output of this Rust program?

Challenge By David Tolnay
Challenge By David Tolnay

A. The program exhibits undefined behavior.

B. The program does not compile.

C. The program is guaranteed to output.

PROJECT SPOTLIGHT 💡

Reth

Reth (short for Rust Ethereum, pronunciation) is a new Ethereum full node implementation that is focused on being user-friendly, highly modular, as well as being fast and efficient. Reth is an Execution Layer (EL) and is compatible with all Ethereum Consensus Layer (CL) implementations that support the Engine API.

Here’s what makes Reth stand out:

  • Built with Rust, Reth boasts impressive performance, making it a great choice for tasks like RPC, MEV, and indexing.
  • Modular Mastermind ensuring every component of Reth is designed to be well-documented, and well-tested library. This allows developers to pick and choose the parts they need, fostering innovation on top of Reth.
  • Reth aims to contribute to the diversity and resilience of the Ethereum network by providing an alternative node implementation.
  • Reth is completely free and open-source, licensed under Apache and MIT licenses. You can use it freely without worrying about licensing restrictions.

Reth aspires to be compatible with various EVM chains beyond just Ethereum. Check out Reth’s repository on GitHub to learn more about the project.

AWESOME LINKS OF THE WEEK 🔗

  1. Angus Morrison wrote The ultimate guide to Rust newtypes.
  2. Willians Faria released hac — an API client written in Rust. Think Postman in the terminal.
  3. Lander wrote an interesting read about Dependency Usage in Rust.
  4. David Lattimore wrote a blog post on various ideas for speeding up Rust compile times.
  5. Olivier Giniaux released GxHash — an extremely fast hardware-accelerated non-cryptographic hashing algorithm.
  6. Wannes Malfait wrote about Computing prime numbers in parallel.
  7. Vhyrro asks, “Are we there yet?” on the road to better programming? his article Moving Beyond Type Systems explores new avenues.
  8. Yoshua Wuyts wrote about creating undroppable types by leveraging context managers.
  9. Andreas Longva’s guide is here to take your Rust parallelism to a whole new ENTER — paradis, that is!
  10. Ryan McKenzie released undname — a new Microsoft symbol demangler written entirely in Rust.

SOLUTION: RUST QUIZ

Answer

C. The program is guaranteed to output: 111222

The Reference describes Rust’s method lookup order. The relevant paragraph is:

Obtain [the candidate receiver type] by repeatedly dereferencing the receiver expression’s type, adding each type encountered to the list, then finally attempting an unsized coercion at the end, and adding the result type if that is successful. Then, for each candidate T, add &T and &mut T to the list immediately after T.

Applying these rules to the given examples, we have:

  • t.f(): We try to find a function f defined on the type T, but there is none. Next, we search the type &T, and find the first implementation of the Or trait, and we are done. Upon invocation, the resolved call prints 1.
  • wt.f(): We search for a function f defined on &T, which immediately succeeds. Upon invocation, the function prints 1.
  • wwt.f(): The search order is &&T -> &&&T -> &mut &&T -> &T, and we're done. Upon invocation, the function prints 1.
  • wwwt.f(): &&&T -> &&&&T. This prints 2.
  • wwwwt.f(): &&&&T. This prints 2.
  • wwwwwt.f(): &&&&&T -> &&&&&&T -> &mut &&&&&T -> &&&&T. This prints 2.

The challenge and solution is by David Tolnay.

Do you have a challenging Rust problem or a helpful tip you’d like to share with fellow Rustaceans? We’d be delighted to feature them in a future issue, with full credit given to you. Submit your challenges or tips to us via email.

Share

BEFORE YOU GO 👋

You’re our biggest fans, and we love to see it.

Here are a few ways you can help us spread the word:

That’s all for now, Rustaceans. Wishing you a productive month ahead.

John & Elley.

--

--