1

Rust 1.65.0 Update Brings Generic Associated Types (GATs)

 1 year ago
source link: https://devm.io/rust/rust-1-65-gats
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

The team at Rust has announced a new version: give a warm welcome to Rust version 1.65.0. The programming language receives new features, including the long-awaited Generic associated types (GATs), a new type of let-else statement, some more stabilized APIs, and more.

Let’s look through the changes included in the Rust 1.65.0 stable release.

Generic Associated Types (GATs)

The update now gives developers the ability to have generic types and lifetimes as a trait’s associated type.

As shown in the release notes, here is a code example:

/// An `Iterator`-like trait that can borrow from `Self`
trait LendingIterator {
    type Item<'a> where Self: 'a;

    fn next<'a>(&'a mut self) -> Option<Self::Item<'a>>;
}

/// Can be implemented over smart pointers, like `Rc` or `Arc`,
/// in order to allow being generic over the pointer type
trait PointerFamily {
    type Pointer<T>: Deref<Target = T>;

    fn new<T>(value: T) -> Self::Pointer<T>;
}

/// Allows borrowing an array of items. Useful for
/// `NdArray`-like types that don't necessarily store
/// data contiguously.
trait BorrowArray<T> {
    type Array<'x, const N: usize> where Self: 'x;

    fn borrow_array<'a, const N: usize>(&'a self) -> Self::Array<'a, N>;
}

New type of let-statement

There is now a new kind of let-statement: let-else statements.

These statements have a refutable pattern, as opposed to normal let statements, which can only use irrefutable patterns.

Additional updates and changes

Other notable changes in the update include:

  • Plain block expressions can now be terminated early by labelling them as a break target
  • Split debug information is now stable for Linux
  • Improved pending job queuing and prioritization in Cargo
  • Rust 1.65.0 stabilizes some APIs and has improved the Backtrace API, so that it may now always capture a stack backtrace
  • The Rust Language Server deprecation in favor of rust-analyzer is now final; users attempting to use RLS will receive a warning message

View the full changelog on GitHub for a comprehensive list of what’s new.

The age of Rust

This release comes on the heels of Rust’s continuous rise in prominence. Most notably, there are currently plans for Rust to enter the Linux kernel in Linux 6.1. This is especially surprising given that C++ has been unable to enter the kernel, and proves that Rust has come a long way since its beginnings as a Mozilla Foundation project.

Besides the developments at Linux, a recent study from OSS Insight analyzed over 5,000,000,000 rows of GitHub event data and Rust developers are quite active. According to the data, Rust has steadily trended upwards in usage for several years and in 2022, it settles in as the 9th most commonly used back-end development language used in all GitHub pull requests.

Additionally, the rust-lang/rust repository is now one of the top 20 most active GitHub repos.

Sarah Schlothauer
Sarah Schlothauer

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK