当前位置:网站首页>Rhai - Rust 的嵌入式脚本引擎
Rhai - Rust 的嵌入式脚本引擎
2022-06-30 16:59:00 【ruonou.com】
基于 Rust 语言丰富和创新的特性,以及超高性能的执行效率,目前在开源界,产生了众多 Rust 语言的嵌入式脚本引擎。Rhai 是新兴的,但创新性较高的一个。Rhai 提供了一种安全、简单的方式向任何应用程序添加以 Rust 语法编写的脚本,但保持了 Rust 语言“零开销”的执行效率。
Rhai 是在 Rust 语言特性之上实现,具有 no-std 特性,以及动态类型。编译时开销非常低,但执行效率很可观:在单核 2.3 GHz 的 Linux 虚拟机上,0.3 秒内,达到了超百万次迭代。
详细来说,Rhai 具有如下特性(下文仅列出了小部分):
- 容易 类似于 Rust + JavaScript,且具有动态类型。 与 Rust 函数和类型紧密集成。 通过外部作用域,将 Rust 变量/常量无损传递到脚本中,无需实现任何特殊特性。 从 Rust 代码内,轻松调用脚本定义的函数。 很少的依赖项,实际必须具有的仅 2 个第三方 Rust crate。
- 极快
非常低的编译时开销。
经评估,在单核 2.3 GHz 的 Linux虚拟机上,0.3秒内,迭代 100 万次。
脚本优化。
- 动态 函数重载。 运算符过载。 用可动态加载的模块,以组织代码库。 函数指针可动态调度。 可以捕获共享变量的闭包。 支持面向对象编程(OOP)。
- 灵活 脚本引擎可以设置为发送+同步(通过同步功能)。 通过 serde crate 提供序列化、反序列化支持。 通过排除不需要的语言特性,以支持最小的构建。 支持大多数构建目标,包括 no-std、WASM。 可自行精确禁用关键字、运算符,以限制语言。 可用作 DSL。
Rhai 在 github 开源,经笔者一段时间的试用,体验效果非常不错。目前,在具体项目中,笔者正进行深入应用:主要聚焦于模板渲染辅助方面。
经笔者深入体验后,故此推荐,感兴趣的朋友可以访问网站:https://rhai.budshome.com,以作详细了解。
边栏推荐
- Php8.0 environment detailed installation tutorial
- 后渗透之文件系统+上传下载文件
- 剑指 Offer 16. 数值的整数次方
- 程序员女友给我做了一个疲劳驾驶检测
- Small Tools(3) 集成Knife4j3.0.3接口文档
- ASP. Net password encryption and password login
- MySQL找不到mysql.sock文件的临时解
- Word中添加代码块(转载)
- Sign up for Huawei cloud proposition in the "Internet +" competition, and you can take many gifts!
- Mo Tianlun salon | Tsinghua qiaojialin: Apache iotdb, originated from Tsinghua, is building an open source ecological road
猜你喜欢

autocad中文语言锁定只读警报怎么解决?

Redis (VII) - sentry

MySQL reports that the column timestamp field cannot be null

Customer relationship CRM management system based on SSH

Redis (III) - transaction

Importing alicloud ECS locally to solve deployment problems

Redis (II) -- persistence

基于SSH的网上商城设计

Volcano engine was selected into the first "panorama of edge computing industry" in China

AnimeSR:可学习的降质算子与新的真实世界动漫VSR数据集
随机推荐
AnimeSR:可学习的降质算子与新的真实世界动漫VSR数据集
Post office - post office issues (dynamic planning)
Vscode status bar statusbar
麻烦问下 Flink支持同步数据到 sqlserver么
New research of HKUST & MsrA: about image to image conversion, finishing is all you need
NFT: 开启加密艺术时代的无限可能
Oneortwo bugs in "software testing" are small things, but security vulnerabilities are big things. We must pay attention to them
Zero foundation can also be an apple blockbuster! This free tool can help you render, make special effects and show silky slides
News management system based on SSM
Redis (IV) - delete policy
Solve the problem of unable to connect to command metric stream and related problems in the hystrix dashboard
Tensorflow2 ten must know for deep learning
Redis (II) -- persistence
Redis (V) - advanced data types
Deep understanding of JVM (VI) -- garbage collection (III)
Helping the ultimate experience, best practice of volcano engine edge computing
The new Post-00 Software Test Engineer in 2022 is a champion
MySQL advanced - Architecture
Research on the principle of Tencent persistence framework mmkv
【机器学习】K-means聚类分析