ITPub博客

首页 > 数据库 > 数据库开发技术 > 【Rust日报】2022-12-28 Rust 中的原生反射

【Rust日报】2022-12-28 Rust 中的原生反射

原创 数据库开发技术 作者:Rust语言中文社区 时间:2022-12-28 23:41:56 0 删除 编辑

Rust 中的原生反射

反射是程序检查自身结构和行为的能力。例如,在 Javascript 中,可以编写迭代任意对象的键值对的程序,或者检查对象是否包含给定名称的字段。Deflect 为 Rust 带来了其中的一些功能。deflect 的核心是它的 Reflect 特性,它适用于所有类型。有了它,您可以:

  • 恢复任何特征对象的具体类型

  • 按名称索引或迭代 a 的字段struct

  • 检查捕获的闭包数据

  • 检查 Rustasync fn 生成器的内部结构

  • 优雅打印任意数据(即使它没有实现Debug!)

  • https://jack.wrenn.fyi/blog/deflect/

文档即代码

Mermaid 工具的支持极大地增强了 rust-docs 和项目文档的整体表现力!Mermaid 是一个允许我们创建流程图、图形、图表、序列图、状态机、甘特图和类图等的工具。例如图表可以添加到函数的 rust-doc 的文档中,显示在 HTML 输出中 cargo doc

#[cfg_attr(doc, aquamarine::aquamarine)]
/// A function showcasing aquamarine defaults
///
/// With aquamarine it's possible to embed Mermaid diagrams into your Rust documentation using the code snippets
///
/// ```mermaid
/// graph LR
/// s([Source]) --> a[[aquamarine]]
/// r[[rustdoc]] --> f([Docs w/ Mermaid!])
/// subgraph rustc[Rust Compiler]
/// a -. inject mermaid.js .-> r
/// end
/// ```
///
/// The diagram is going to be located in place of the code snippet
///
/// Dark mode is automatically enabled if `dark` or `ayu` rustdoc theme is selected.
///
/// You might need to reload the page to redraw the diagrams after changing the theme.
pub fn example() {}

  • https://mermaid.js.org/intro/

Cnosdb 时序数据库行协议解析

🥳CnosDB Rust课程精彩继续🥳 🦴 本期主题:实战!解析行协议 2 (Rust parser combinator)
👾本节课我们将继续深入实战阶段,做好准备,前方高能
  1. 解析bool类型
  2. 解析整型
内容概要: 本期继续实战解析行协议,行协议的filed类型有5种,分为bool,有符号整型,无符号整型,浮点型,字符串,我们将依次为大家解析
Make Some Noise!
有趣的知识,等你来发掘~
Rust课程, 本周三,12.28晚7点 大家依旧相约直播间https://live.bilibili.com/23768194

From 日报小组 侯盛鑫 mock
社区学习交流平台订阅:
  • Rust.cc 论坛: 支持 rss
  • 微信公众号:Rust 语言中文社区

原文作者:Rust语言中文社区;如有侵权,请联系管理员删除。

请登录后发表评论 登录
全部评论

注册时间:2020-06-11

  • 博文量
    1769
  • 访问量
    718516