前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Rust日报】 2019-08-16:Rust 1.37.0 稳定版已发布

【Rust日报】 2019-08-16:Rust 1.37.0 稳定版已发布

作者头像
MikeLoveRust
发布2019-08-19 12:00:53
4380
发布2019-08-19 12:00:53
举报

Rust 1.37.0 稳定版已发布

  • 現在可以使用 type 製作別名
代码语言:javascript
复制
type ByteOption = Option<u8>;

fn increment_or_zero(x: ByteOption) -> u8 {
    match x {
        ByteOption::Some(y) => y + 1,
        ByteOption::None => 0,
    }
}
  • 而在實作(实现)函數中 Self 可以當成目前結構的別名
代码语言:javascript
复制
impl Coin {
    fn value_in_cents(&self) -> u8 {
        match self {
            Self::Penny => 1,
            Self::Nickel => 5,
            Self::Dime => 10,
            Self::Quarter => 25,
        }
    }
}
  • 現在可以有匿名的變數在巨集(宏)中
代码语言:javascript
复制
/// Type size assertion where the first parameter
/// is a type and the second is the expected size.
#[macro_export]
macro_rules! static_assert_size {
    ($ty:ty, $size:expr) => {
        const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
        //    ^ Note the underscore here.
    }
}

static_assert_size!(Option<Box<String>>, 8); // 1.
static_assert_size!(usize, 8); // 2.
現在程式可以根據實際的執行情況最佳化編譯,神奇的功能!

首先編譯時 rustc 加入 -C profile-generate

然後執行這個程式跑一跑你的測試資料後會產生記錄檔

再來第二次編譯 rustc 加入 -C profile-use

會根據你剛剛跑的結果來最佳化編譯

  • 現在將編譯出執行檔做為預設(缺省)行為

如果你沒打 --bin 也可以編

  • enum 也可以對齊了
代码语言:javascript
复制
#[repr(align(16))]
enum Align16 {
    Foo { foo: u32 },
    Bar { bar: u32 },
}
  • 下面的函數穩定了
代码语言:javascript
复制
BufReader::buffer and BufWriter::buffer
Cell::from_mut
Cell::as_slice_of_cells
DoubleEndedIterator::nth_back
Option::xor
[{i,u}{8,16,32,64,128,size}::reverse_bits] and Wrapping::reverse_bits
slice::copy_within

read more

Grand Star v0.6.0

任天堂也用Rust了。這是任天堂的 rust tool chain跟庫的集合

這些庫還不成熟,還在開發中,非常需要有時間的人幫忙開發

歡迎大家的加入

  • reddit 讨论
  • GitHub Org: https://github.com/rust-wii/

Yew v0.8

  • 現在html <div class="marker" /> 可以使用/>來對tag做描述,
  • 現在 SVG 命名空間可以使用
  • Properties 可以被整合編譯

詳細請看 changelog

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-08-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Rust语言学习交流 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Rust 1.37.0 稳定版已发布
    • 現在程式可以根據實際的執行情況最佳化編譯,神奇的功能!
    • Grand Star v0.6.0
    • Yew v0.8
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档