欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Serverless技术:Rust语言使用WASM和Cl-Rust 1.40.0的最新进展

最编程 2024-01-16 07:00:57
...

新增了一些新特性

  1. 不詳細的

#[non_exhaustive] structs, enums, and variants

這表示當前的屬性有缺少,要增加屬性欄位,沒增加是會出現錯誤的。

範例看到 beta 依賴 alhpa

// alpha/lib.rs:

#[non_exhaustive]
struct Foo {
   pub a: bool,
}

enum Bar {
   #[non_exhaustive]
   Variant { b: u8 }
}

fn make_foo() -> Foo { ... }
fn make_bar() -> Bar { ... }

// beta/lib.rs:

let x = Foo { a: true }; //~ ERROR
let Foo { a } = make_foo(); //~ ERROR

// `beta` will still compile when more fields are added.
let Foo { a, .. } = make_foo(); //~ OK


let x = Bar::Variant { b: 42 }; //~ ERROR
let Bar::Variant { b } = make_bar(); //~ ERROR
let Bar::Variant { b, .. } = make_bar(); //~ OK
                  // -- `beta` will still compile...
  1. macro 的改善

現在可以這樣寫 expand_to_type 是 procedural macro

type Foo = expand_to_type!(bar);

extern 裡面也可以有 macro

macro_rules! make_item { ($name:ident) => { fn $name(); } }

extern {
   make_item!(alpha);
   make_item!(beta);
}
  1. Rust 2015的借用檢查警告會變成錯誤

  2. 更多 const fn 函數進入標準庫

  3. 還有其它一些函數跟macro也穩定了

Read more