【Rust 日报】2022-10-23 tachyonix:一个高性能异步计算框架

tachyonix:异步多生产单消费有界通道

这个库是 Asynchronix 的一个分支,它持续努力地构建用于系统仿真的高性能异步计算框架。

这是一个简洁的异步通道,以快速著称,但也不会在正确性和质量方面取巧。它的性能主要来自于对 MPSC 用例的关注和一些精心的优化,包括:

  • 为全队列和空队列事件积极优化通知原语。

  • 发送者一旦创建就不会再分配,即使对于被阻止的发送者 / 接收者通知。

  • 没有任何自旋锁,并且热点路径(程序中那些会频繁执行到的代码)中没有互斥锁。

  • 针对单个接收器优化的底层队列。

示例:

use tachyonix;
use futures_executor::{block_on, ThreadPool};

let pool = ThreadPool::new().unwrap();

let (mut s, mut r) = tachyonix::channel(3);

block_on( async move {
    pool.spawn_ok( async move {
        assert_eq!(s.send("Hello").await, Ok(()));
    });
    
    assert_eq!(r.recv().await, Ok("Hello"));
});

GitHub:https://github.com/asynchronics/tachyonix

rsre:重命名工具

使用指南:

USAGE:
    rsre FILE/DIRECTORY NEW_FULL_NAME

OPTIONS:
    -h, --help     Print help information
    -V, --version  Print version information

示例:

# with mv
mv ../../foo/bar/bat/foo.txt ../../foo/bar/bat/bar.txt
# with rsre
rsre ../../foo/bar/bat/foo.txt bar.txt

GitHub:https://github.com/TheAwiteb/rsre

exun:错误处理

有许多我们不希望发生的错误,但即便错了我们也不希望 panic,当然我们也不想花太多时间处理意外错误。这就是本项目的用途,你可以保留意外错误,直到以后再担心它们。

示例:

use exun::*;

fn foo(num: &str) -> Result<i32, RawUnexpected> {
    // 使用 `unexpect` 表示我们预计不会发生这个错误
    let num = num.parse::<i32>().unexpect()?;
    Ok(num)
}
use std::error::Error;
use std::fmt::{self, Display};

use exun::*;

#[derive(Debug)]
struct NoNumberError;

impl Display for NoNumberError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "no number provided")
    }
}

impl Error for NoNumberError {}

fn foo(num: Option<&str>) -> Result<i32, Expect<NoNumberError>> {
    let num = num.ok_or(NoNumberError)?; // 预计这可能会返回一个错误
    let num = num.parse::<i32>().unexpect()?; // 但我们认为这个数字是可以解析的
    Ok(num)
}
use std::error::Error;
use std::fmt::{self, Display};
use std::num::ParseIntError;

use exun::*;

#[derive(Debug)]
struct NoNumberError;

impl Display for NoNumberError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "no number provided")
    }
}

impl Error for NoNumberError {}

fn foo(num: Option<&str>) -> Result<i32, Exun<&str, ParseIntError>> {
    // 预计可能不会得到一个数字,所以这样处理
    let num = match num {
        Some(num) => num,
        None => return Err(Expected("no number provided")),
    };

    // 但是,我们希望这个数字是可以解析的
    match num.parse() {
        Ok(int) => Ok(int),
        Err(e) => Err(Unexpected(e))
    }
}

GitHub:https://github.com/botahamec/exun

StarRust:太空射击游戏

使用 Rust 和 Bevy 制作的开源横向展开的太空射击游戏。

Demo:https://larsdu.github.io/StarRust/

GitHub:https://github.com/LarsDu/StarRust

cosmic-text:多行文本变形和渲染

COSMIC Text 提供了高级文本变形、布局和渲染。这些都被包含在一个简单抽象中。

  • 文本变形由 rustybuzz 提供,并支持各种高级变形操作。

  • 渲染由 swash 提供,它支持连字和彩色表情符号。

  • 布局是在安全的 Rust 中自定义实现的,支持双向文本。

GitHub:https://github.com/pop-os/cosmic-text

学习资源

  • 12 分钟 SQLx(比 Diesel 更简单的替代品):https://www.youtube.com/watch?v=vLcoW408QvE

  • Rust 中的快速原型设计(像 Python 一样「快」,像 C 一样「快」):https://www.youtube.com/watch?v=X7Dsu0oRk0U


From 日报小组 长琴

社区学习交流平台订阅:

  • Rustcc 论坛:支持 rss

  • 微信公众号:Rust 语言中文社区

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值