BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Rust 1.49 Released with Tier-1 Support of 64-Bit ARM Linux

Rust 1.49 Released with Tier-1 Support of 64-Bit ARM Linux

This item in japanese

Bookmarks

The Rust team released on the eve of last year Rust 1.49. The new version of Rust features 64-bit ARM support and minor language enhancements.

Rust’s unions can now implement the Drop trait (whose drop method is called automatically when an object goes out of scope). Union fields that developers want to manually drop are annotated with a ManuallyDrop<T> type. The Rust documentation explains:

A union declaration uses the same syntax as a struct declaration, except with union in place of struct.

#[repr(C)]
union MyUnion {
   f1: u32,
   f2: f32,
}

When a union is dropped, it cannot know which of its fields needs to be dropped. For this reason, all union fields must either be of a Copy type or of the shape ManuallyDrop<_>. This ensures that a union does not need to drop anything when it goes out of scope.

One maintainer detailed one benefit of the new language feature:

It’s valuable for correctly implementing “atomic state machine” patterns, common in low-level async code, in which you have a tagged union with an atomically updated tag (with a locked state as well, etc.).

Uninhabited enums (e.g, enum Foo { }) can now be cast to integers. The change addresses edge cases that appeared in macro code.

Rust developers can also now bind by reference and by move in patterns. A primary use case is to borrow individual components of a type:

fn main() {
    #[derive(Debug)]
    struct Person {
        name: String,
        age: u8,
    }

    let person = Person {
        name: String::from("Alice"),
        age: 20,
    };

    // `name` is moved out of person, but `age` is referenced
    let Person { name, ref age } = person;

    println!("The person's age is {}", age);

    println!("The person's name is {}", name);

    // Error! borrow of partially moved value: `person` partial move occurs
    //println!("The person struct is {:?}", person);

    // `person` cannot be used but `person.age` can be used as it is not moved
    println!("The person's age from person struct is {}", person.age);
} 

The new version of Rust promotes the aarch64-unknown-linux-gnu target to Tier 1 support. This means that developers using 64-bit ARM systems with Linux have the assurance that a full test-suite has been run for every change merged into the compiler. Prebuilt binaries are also made available. The team expects that the 64-bit ARM support will benefit workloads spanning from embedded to desktops and servers. The release note explained:

This is an important milestone for the project, since it’s the first time a non-x86 target has reached Tier 1 support: we hope this will pave the way for more targets to reach our highest tier in the future.

The new Rust version also adds Tier 2 support of Apple M1 systems (aarch64-apple-darwin target) and 64-bit ARM devices running Windows (aarch64-pc-windows-msvc target).

Developers with a previous version of Rust installed via rustup can upgrade to Rust 1.49.0 with the following command:

rustup update stable

The detailed release note is available online.

Rate this Article

Adoption
Style

BT