Builder Lite: 精简 builder 模式

本文介绍了 builder 模式的一个表亲: 精简 builder 模式.

示例代码如下.

pub struct Shape {
position: Vec3,
geometry: Geometry,
material: Option<Material>,
}

impl Shape {
pub fn new(geometry: Geometry) -> Shape {
Shape {
position: Vec3::default(),
geometry,
material: None,
}
}

pub fn with_position(mut self, position: Vec3) -> Shape {
self.position = position;
self
}

pub fn with_material(mut self, material: Material) -> Shape {
self.material = Some(material);
self
}
}
// 调用示例
let shape = Shape::new(Geometry::Sphere::with_radius(1))
.with_position(Vec3(0, 9, 2))
.with_material(Material::SolidColor(Color::Red));

原文链接: https://matklad.github.io/2022/05/29/builder-lite.html

async/await 在 Rust 中场景介绍

其他编程语言中的 async/await 特性似乎比Rust中的更直观一些, 例如 JavaScript.

本文介绍了 Rust 中的 async/await 的一些场景.

原文链接: https://www.geekabyte.io/2022/05/a-neophytes-introduction-to-asyncawait.html

duf: 简单的文件服务器

​duf​​ 是一个简单的 file server. 支持以下特性:

  • 静态文件服务器
  • 以 zip 方式下载文件
  • 文件搜索
  • 文件上传
  • 文件删除
  • 基础权限
  • 方便使用 curl 使用
  • ...

【Rust日报】2022-05-30 精简 builder 模式_github

github 地址: https://github.com/sigoden/duf

Rust编写的小游戏

这是 Rust 编写的一个小游戏,完成度比较高, 并且开源了源代码, 感兴趣的小伙伴可以自取.

游戏源码: https://github.com/kennoath/wizrad

油管视频: https://www.youtube.com/watch?v=s8SpOB7rlAA

--


社区学习交流平台订阅:

  • Rustcc论坛: 支持rss
  • 微信公众号:Rust语言中文社区