前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Rust日报】Rust 单元测试入门

【Rust日报】Rust 单元测试入门

作者头像
MikeLoveRust
发布2024-03-07 12:44:27
1250
发布2024-03-07 12:44:27
举报

Rust 单元测试入门

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

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

原文链接 https://dev.to/thiagomg/a-simple-guide-to-unit-tests-in-rust-4h8l

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

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

原文链接 https://troyni.com/graphpu 以及 github 地址 https://github.com/latentcat/graphpu

sh: 命令行辅助宏

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

代码示例

代码语言:javascript
复制
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 https://docs.rs/sh/0.2.1/sh/

  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/
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2024-03-06,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Rust 单元测试入门
  • GraphPU: Rust编写的 3D GPU 图形可视化应用程序
  • sh: 命令行辅助宏
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档