应用 Rust 模板

Note

本节假设你已经通过 flutter create [my_app_name] 创建了一个 Flutter 项目。您可以从这份优秀的 Flutter 教程获取更多指导。

首先,将此框架添加到您的 Flutter 项目中。 First of all, add this framework to your Flutter project.

CLI
flutter pub add rinf

安装命令行可执行文件,以便在 CLI 中轻松运行 Rinf 命令。[1] Now install the command executable to easily run Rinf commands in the CLI.[1]

CLI
cargo install rinf_cli

然后,在你的 Flutter 项目目录下运行以下命令:

CLI
rinf template

执行该命令后,您将获得新增的文件和文件夹,作为 Rust 起始模板。

Folder Tree
    my_flutter_project/
    ├── android/
    ├── ios/
    ├── lib/
*   │   ├── main.dart
    │   └── ...
    ├── linux/
+   ├── native/
+   │   ├── hub/
+   │   │   ├── src/
+   │   │   └── Cargo.toml
+   │   └── README.md
    ├── web/
    ├── windows/
*   ├── .gitignore
+   ├── Cargo.toml
*   ├── pubspec.yaml
*   ├── README.md
    └── ...

实际代码中写有各种注释,帮助你理解整体结构。

如果您已有想要在此使用的 Rust crate,只需将其放入 native 目录,并将其设置为 hub crate 的依赖项即可。

现在,进入 native/hub/src/lib.rs,你就可以开始编写 Rust 代码了!

示例代码供参考,请参见此处,如果无法打开也可以点击此处查看码云上的镜像仓库。