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

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 使用

  • ...

248e087d4a1baf90f47d3c7a7936cf58.png

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

Rust编写的小游戏

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

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

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

--

From 日报小组 BobQin,FBI小白

社区学习交流平台订阅:

  • Rustcc论坛: 支持rss

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值