3 min read

Yesterday, the Rust team announced the release of Rust 1.32 in a blog post. The new version of the Rust programming language brings improvements to the quality of life, switches to the default allocator, and makes more functions const.

Addition of the dbg macro in Rust 1.32

If you are a “print debugger”, you must have wanted to print out some value while working on code. Using something like println!(“{:?}”, x); isn’t fast enough. It is also a bit too much just to simply show the value of x. Also, there is no context here, if there are several println! statements, it is hard to distinguish between them. Rust now has a new package called dbg specifically for this purpose:

fn main() {
   let x = 5;   
   dbg!(x);
}

On running the above code, you will get:

[src/main.rs:4] x = 5

In the output, you will see the file, line number, name, and value. While println! prints to the standard output, the dbg! function prints to the stderr. dbg! even works in more complex circumstances like factorial, iterations, etc.


jemalloc is removed in Rust 1.32

In Rust’s initial years, it had a large Erlang type runtime. The developers then chose jemalloc instead of the system allocator for better performance. Over time, most of this runtime was removed except jemalloc. jemalloc was kept for users who would still need it. While it has great performance in most cases, it was not always the case. It adds 300kb to every Rust binary and has other issues. The core developers also thought it was strange that a systems language does not default to the system allocator. Hence Rust 1.28 had shipped with a global allocator. The work for using a system allocator is now finished and it can be used for all Rust programs now. jemalloc can still be used if you want to, via a crate in the Cargo.toml.

Module improvements

The last two Rust releases had some performance improvements to the module system. Rust 1.32 comes with something called “uniform paths” which allows import path statements to be resolved the same way as non-import paths. This was previously invalid. Efforts to revise the system module is now complete and the following code will now work.

enum Color { Red, Green, Blue }
use Color::*;

Macro improvements

A new literal string matcher is added. It matches against literals of any type. This includes string literals, numeric literals, and char literals. In Rust 2018 edition, macro_rules can also use ? to match 0 or 1 repetitions of the pattern.

Library changes

Other than the dbg! library, 19 functions were made cont. Now, all integral numeric primitives give conversion functions to and from byte-arrays that have specified endianness. There are six functions named as: to__bytes and from__bytes, in which is one of the following:

  • ne – native endianness
  • le – little endian
  • be – big endian

Cargo now has cargo_c as an alias for cargo_check and now usernames in registry URLs are allowed.

These were the highlights of the changes in Rust 1.32, for a complete list of changes and fixes, visit the release notes.

Read next

How has Rust and WebAssembly evolved in 2018

Rust Survey 2018 key findings: 80% developers prefer Linux, WebAssembly growth doubles, and more

Red Hat announces full support for Clang/LLVM, Go, and Rust


Subscribe to the weekly Packt Hub newsletter. We'll send you the results of our AI Now Survey, featuring data and insights from across the tech landscape.