【Rust 日报】2020-03-04:Rust blog :模式匹配改进

嵌入式开发中的 async/await

这篇博客中讨论了为什么"async/await"对于嵌入式开发来说是比较重要的一个功能. 文章从一下几个角度来分析:

  • 从阻塞到非阻塞

  • 多任务处理

  • 线程

  • 数据共享

  • ...

详情:https://ferrous-systems.com/blog/async-on-embedded/

几个小技巧让你的 Rust 代码性能

不用改动代码,只通过几个技巧就能提高你的 Rust 项目运行速度,比如在 `Cargo.tom` 文件中 [profile.release] 下根据情况更改一些字段或许就可以提升你的项目性能:

  • lto = "fat"

  • codegen-units = 1

  • target-cpu = "native"

  • ...

详细介绍:https://deterministic.space/high-performance-rust.html

Firecracker: serverless 应用的轻量级虚拟化

详情: https://blog.acolyer.org/2020/03/02/firecracker/

Rust blog:近期以及未来的模式匹配改进

Rust 官方博客介绍了即将了即将应用于stable Rust 的模式匹配新特性

Subslice 模式匹配,[head, tail @ ..]

.. 意味着可变间隔,例如

fn recover_attrs_no_item(&mut self, attrs: &[Attribute]) -> PResult<'a, ()> {
    let (start, end) = match attrs {
        [] => return Ok(()),
        [x0] => (x0, x0),
        [x0, .., xn] => (x0, xn),
    };
    let msg = if end.is_doc_comment() {
        "expected item after doc comment"
    } else {
        "expected item after attributes"
    };
    let mut err = self.struct_span_err(end.span, msg);
    if end.is_doc_comment() {
        err.span_label(end.span, "this doc comment doesn't document anything");
    }
    if let [.., penultimate, _] = attrs {
        err.span_label(start.span.to(penultimate.span), "other attributes here");
    }
    Err(err)
}

其中 [x0, .., xn] 就表示匹配第一个以及最后一个元素而忽略中间的所有元素.

另一种用法是可以将subslice约束为一个变量,比如如果我们希望某个函数除了最后一个参数之外的参数不能为 ... 那么可以这样写:

match &*fn_decl.inputs {
    ... // other arms
    [ps @ .., _] => {
        for Param { ty, span, .. } in ps {
            if let TyKind::CVarArgs = ty.kind {
                self.err_handler().span_err(
                    *span,
                    "`...` must be the last argument of a C-variadic function",
                );
            }
        }
    }
}

这里的 ps @ .. 就表示忽略参数的最后的一个元素而将剩下的元素转化为 变量 ps

其他还有

  • Nested OR-patterns

  • Bindings after @

  • Combining by-move and by-ref bindings

详情: https://blog.rust-lang.org/inside-rust/2020/03/04/recent-future-pattern-matching-improvements.html


From 日报小组 @挺肥

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值