【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));

async/await 在 Rust 中场景介绍

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

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

duf: 简单的文件服务器

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

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

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
Builder Lite: 精简 builder 模式 本文介绍了 builder 模式的一个表亲: 精简 builder 模式. 示例代码如下. pub struct Shape { position: Vec3, geometry: Geometry, material: Option , } 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)); async/await 在 Rust 中场景介绍 其他编程语言中的 async/await 特性似乎比Rust中的更直观一些, 例如 JavaScript. 本文介绍了 Rust 中的 async/await 的一些场景. duf: 简单的文件服务器 duf 是一个简单的 file server. 支持以下特性: 静态文件服务器 以 zip 方式下载文件 文件搜索 文件上传 文件删除 基础权限 方便使用 curl 使用 ... 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
经验分享 程序员 微信小程序 职场和发展