• 【Rust 日报】2022-06-19 Rust 1.63 新特性令人期待


    Rust 1.63新特性

    Rust 标准库 1.63 增加了一个期待已久的功能:scoped thread(作用域线程)。与 thread::spawn() 不同,这个新特性允许线程借用局部变量,而不仅仅是静态变量。借用官方例子:

    1. use std::thread;let mut a = vec![1, 2, 3];let mut x = 0;
    2. thread::scope(|s| {
    3. s.spawn(|| { println!("hello from the first scoped thread"); // borrow `a` here
    4. dbg!(&a);
    5. });
    6. s.spawn(|| { println!("hello from the second scoped thread"); // mutably borrow `x`, because no other threads are using it
    7. x += a[0] + a[2];
    8. }); println!("hello from the main thread");
    9. });// after the scope, can modify and access the variables againa.push(4);assert_eq!(x, a.len());

    更多可查看官方文档:https://doc.rust-lang.org/nightly/std/thread/fn.scope.html

    另外,Mutex::newRwLock::new 和 Condvar::new 都是 const function。这意味着现在可以将这些类型用作静态变量,而不再需要 lazy_static 或 once_cell 或其他解决方法。

    Rust 1.63 将会在 8 月 11 日发布。

    readyset:一个轻量SQL缓存引擎

    ReadySet 是一个轻量级的 SQL 缓存引擎,可预先计算经常访问的查询结果,并在数据库中的基础数据更改时自动使这些结果随时间推移保持最新。ReadySet 与 MySQL 和 Postgres 有线兼容,无需更改代码即可采用。ReadySet 同时充当 SQL 缓存和代理 – 当首次将 ReadySet 连接到应用程序时,它默认将所有查询代理到后面的数据库,因此它不会更改应用程序的行为。

    20352caf2c0c0d9c034fda913186a8eb.png

    主页:https://readyset.io/

    文档:https://docs.readyset.io/

    GitHub:https://github.com/readysettech/readyset

    ante:一个安全简单的系统语言

    Ante 是一种低级别的函数式语言,用于探索细化类型、生命周期推理和其他有趣的功能。

    1. type Person = name: string, job: ref string// Infer that the data referenced via `&` should not be freed inside this functionmake_person name =
    2. Person name &"programmer"// bob is only used at this scope, so it can be safely freed afterwardbob = make_person "bob"// unlike ownership systems, aliasing is allowed with lifetime inferencebob_twin = bob
    3. assert (bob.name == bob_twin.name)

    语言概览:https://antelang.org/docs/language/

    主页:http://antelang.org/

    GitHub:https://github.com/jfecher/ante

    quartz.rs:一个小巧的调度库

    简单示例:

    1. use std::{thread, time::Duration};struct MyTask;impl quartz_sched::Job for Box<MyTask> { fn execute(&self) { println!("[+] Executing 'MyTask'");
    2. } fn description(&self) -> String { "my task".to_string()
    3. } fn key(&self) -> i64 { 43
    4. }
    5. }fn main() { let mut sched: quartz_sched::Scheduler = quartz_sched::Scheduler::new(); // start the scheduler
    6. // spawns execution and feeder threads
    7. sched.start(); // execute after duration N
    8. sched.schedule_task(quartz_sched::schedule_task_after(
    9. Duration::from_secs(1), Box::new(MyTask),
    10. )); // get scheduled job meta info from scheduler
    11. match sched.get_scheduled_job(/*key*/ 43) { Some(job) => { println!("[+] Next run at tick: {}", &job.next_runtime);
    12. } None => {}
    13. };
    14. thread::sleep(Duration::from_secs(20)); // scheduler will stop after getting dropped
    15. // alternatively, call sched.stop() to stop
    16. // the scheduler.
    17. // delete task associated with key from scheduler
    18. _ = sched.delete_task(43);
    19. }

    GitHub:https://github.com/mitghi/quartz.rs


    From 日报小组 长琴

    社区学习交流平台订阅:

    • Rustcc 论坛:支持 rss

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

  • 相关阅读:
    SpringFramewrok (1)
    ubuntu 系统升级问题
    STM32CubeMX教程21 CAN - 双机通信
    JS 之 前端对象详解
    插入排序 python实现
    基于SSM的进存销管理系统
    MyEclipse 2017 安装与pj
    恒峰—高压森林应急消防泵:保障森林安全
    软考-虚拟专用网原理与应用
    react中的this指向问题
  • 原文地址:https://blog.csdn.net/u012067469/article/details/125364813