Software-update: Rust 1.83.0

Rust logo (79 pix)Rust is een programmeertaal bedacht door Graydon Hoare en oorspronkelijk ontwikkeld door Mozilla. Het is deels geïnspireerd op de programmeertaal C, maar kent syntactische en semantische verschillen. Het focust op veiligheid en moet moderne computersystemen efficiënter te benutten. Het wordt ingezet door onder andere Cloudflare, OVH, Mozilla, Deliveroo, Coursera, AppSignal en Threema. Versie 1.83 is uitgebracht en de releasenotes voor die uitgave kunnen hieronder worden gevonden.

New const capabilities

This release includes several large extensions to what code running in const contexts can do. This refers to all code that the compiler has to evaluate at compile-time: the initial value of const and static items, array lengths, enum discriminant values, const generic arguments, and functions callable from such contexts (const fn).

References to statics. So far, const contexts except for the initializer expression of a static item were forbidden from referencing static items. This limitation has now been lifted:

static S: i32 = 25;
const C: &i32 = &S;

Note, however, that reading the value of a mutable or interior mutable static is still not permitted in const contexts. Furthermore, the final value of a constant may not reference any mutable or interior mutable statics:

static mut S: i32 = 0;

const C1: i32 = unsafe { S };
// error: constant accesses mutable global memory

const C2: &i32 = unsafe { &S };
// error: encountered reference to mutable memory in `const`

These limitations ensure that constants are still "constant": the value they evaluate to, and their meaning as a pattern (which can involve dereferencing references), will be the same throughout the entire program execution.

That said, a constant is permitted to evaluate to a raw pointer that points to a mutable or interior mutable static:

static mut S: i32 = 64;
const C: *mut i32 = &raw mut S;

Mutable references and pointers. It is now possible to use mutable references in const contexts:

const fn inc(x: &mut i32) {
    *x += 1;
}

const C: i32 = {
    let mut c = 41;
    inc(&mut c);
    c
};

Mutable raw pointers and interior mutability are also supported:

use std::cell::UnsafeCell;

const C: i32 = {
    let c = UnsafeCell::new(41);
    unsafe { *c.get() += 1 };
    c.into_inner()
};

However, mutable references and pointers can only be used inside the computation of a constant, they cannot become a part of the final value of the constant:

const C: &mut i32 = &mut 4;
// error[E0764]: mutable references are not allowed in the final value of constants

This release also ships with a whole bag of new functions that are now stable in const contexts (see the end of the "Stabilized APIs" section).

These new capabilities and stabilized APIs unblock an entire new category of code to be executed inside const contexts, and we are excited to see how the Rust ecosystem will make use of this!

Stabilized APIs

These APIs are now stable in const contexts:

Other changes

Check out everything that changed in Rust, Cargo, and Clippy.

Rust

Versienummer 1.83.0
Releasestatus Final
Website The Rust Programming Language Blog
Download https://www.rust-lang.org/install.html
Licentietype Voorwaarden (GNU/BSD/etc.)

Door Bart van Klaveren

Downloads en Best Buy Guide

29-11-2024 • 09:00

5

Submitter: danmark_ori

Bron: The Rust Programming Language Blog

Update-historie

27-06 Rust 1.88.0 8
16-05 Rust 1.87.0 1
04-04 Rust 1.86.0 0
21-02 Rust 1.85.0 0
31-01 Rust 1.84.1 0
10-01 Rust 1.84.0 0
29-11 Rust 1.83.0 5
09-'24 Rust 1.81.0 1
07-'24 Rust 1.80.0 8
04-'24 Rust 1.77.2 7
Meer historie

Reacties (5)

5
5
5
0
0
0
Wijzig sortering
Als voormalig Clipper en Visual Object's prutser, vindt ik Rust erg interessant, ik mis alleen een IDE/Tool/Crate om een scherm layout en menu te bouwen, zoals in CAVO. Iemand een tip?
"Als voormalig Clipper en Visual Object's prutser, vindt ik Rust erg interessant" - ik snap niet helemaal waarom. Het is echt appels en peren vergelijken.
In VO hadden we alles in een, Menu builder, Window builder en een database server. In Rust is alles nog steeds apart omdat iedereen zijn eigen implementatie maakt. Dat is waarschijnlijk het nadeel van open source versus een bedrijf als Nantucket en later Computer Associates, waar ik 20 jaar gewerkt heb.
Ik baal ook nog steeds dat onze Object Database, Jasmine, op niets uitgelopen is. Als we de source in Rust zouden kunnen herschrijven, dan is misschien de snelheid ook geen probleem meer, zeker ook omdat we nu meer cores in een CPU hebben.
Waarom gebruik je niet Egui, of gtk-rs, of Dioxus of Tauri?
@nubro01 Een (crossplatform) applicatie met een GUI maken staat ook op mijn verlanglijstje, maar een eenduidige keuze voor de GUI hebt ik nog niet gemaakt. Kijk vooral eens op areweguiyet. Zelf vermoed ik dat slint.dev het meest interressant voor mij.

[Reactie gewijzigd door scholtnp op 29 november 2024 13:33]

Op dit item kan niet meer gereageerd worden.