So What's Up with Microsoft's (and Everyone Else's) Love of Rust? 的博文,更多详情请看:https://visualstudiomagazine.com/articles/2020/06/02/rust-love.aspx?m=1ct_python!ct_python!是一个 Rust 宏,用于在编译时执行 Python 代码,并将输出作为 Rust
代码插入到 Rust 程序中。它是
inline-python【https://github.com/fusion-engineering/inline-python】的一部分。#![feature(proc_macro_hygiene)]use ct_python::ct_python;static SIN_2: f64 = ct_python! {from math import sinprint(sin(2))};ct_python! {print("type num = f64;")}fn main() {assert_eq!(num::sin(2.0), SIN_2);}
syn(https://github.com/dtolnay/syn) 是一个解析库,用于将 Rust 令牌流解析为 Rust 源代码的语法树。syn-rsx 基于 syn,是一个类似于 JSX 的 TokenStreams 解析器。解析的结果是嵌套的 Node 结构,类似于浏览器 DOM,其中节点名称和值是支持构建 proc 宏的 syn 表达式。并提供了用于自定义解析行为的 ParserConfig。use quote::quote;use syn_rsx::parse2;let tokens = quote! {<div foo={bar}><div>"hello"</div><world /></div>};let nodes = parse2(tokens, None).unwrap();let node = &nodes[0];assert_eq!(node.attributes[0].name_as_string().unwrap(), "foo");let children = &node.children;assert_eq!(children.len(), 2);assert_eq!(children[0].children[0].value_as_string().unwrap(), "hello");assert_eq!(children[1].name_as_string().unwrap(), "world");
这是油管上的一个较短视频教程,约 20 分钟,结合实际例子,讲述使用 Rocket 框架进行简短、易用、类型安全的 Rust web 开发。地址:https://www.youtube.com/watch?v=tjH0Mye8U_A&feature=youtu.be
原文作者:Rust语言中文社区;如有侵权,请联系管理员删除。