< 返回版块

gensmusic 发表于 2024-03-04 18:22

Rust 单元测试入门

软件中一个非常重要的部分是单元测试,毕竟,它们帮助我们验证那些我们脑海中的案例是否确实被正确实现,同时也确保了将来可能会修改我们代码的下一个幸运者能够自信他们的改动不会破坏应用程序

本文介绍了如何编写基本的单元测试.

原文链接

GraphPU: Rust编写的 3D GPU 图形可视化应用程序

“GraphPU” 是一款 3D GPU 图形可视化应用程序。基于 Rust 语言和 WebGPU 开发的渲染框架和高性能计算 (HPC) 算法,使得这个应用能够在 Vulkan 和 Metal 平台上实时模拟和渲染数百万个节点和边。演示包括了多个大规模图形数据集,包括电影语义学、电子邮件、大型网站结构、个人微信关系以及社交媒体连接。观众可以通过控制器旋钮与这些数据进行互动

img

原文链接 以及 github 地址

sh: 命令行辅助宏

sh 是一个用于运行外部命令的宏。它提供了将输入和输出管道到变量的功能,以及使用 Rust 表达式作为程序参数的功能。

代码示例

let world = "world";
let mut out = String::new();
sh!(echo hello {world} > {&mut out});
assert_eq!(out, "hello world\n");

// We can also pipe a String/&str or Vec<u8>/&[u8] to a command
out.clear();
let input = "foo bar baz";
sh!(cat < {input} > {&mut out});
assert_eq!(&out, input);

// We can execute many commands at once
let mut out1 = String::new();
let mut out2 = String::new();
let mut out3 = String::new();

sh! {
  echo hello world 1 > {&mut out1}; // Note the `;`
  echo hello world 2 > {&mut out2};
  echo hello world 3 > {&mut out3};
}

assert_eq!(&out1, "hello world 1\n");
assert_eq!(&out2, "hello world 2\n");
assert_eq!(&out3, "hello world 3\n");

sh crate

  1. https://readrust.net
  2. https://reddit.com/r/rust
  3. twitter : #rustlang https://twitter.com/search?q=%23rustlang&src=recent_search_click&f=live
  4. https://medium.com/tag/rustlang
  5. https://this-week-in-rust.org/

--

From 日报小组 BobQ, FBI小白

社区学习交流平台订阅:

评论区

写评论

还没有评论

1 共 0 条评论, 1 页