flutter_rust_bridge: 用于 Flutter 和 Rust 的高级内存安全绑定生成器

High-level memory-safe binding generator for Flutter/Dart <-> Rust

Rust Package Flutter Package Stars CI Example Codacy Badge

Logo

想把 Flutter(一个跨平台的热重载快速开发 UI 工具包)和 Rust(一种使每个人都能构建可靠和高效软件的语言)的优点结合起来?它来了!

🚀 优势

  • 内存安全: 完全不用考虑 malloc 和 free.
  • 特性丰富:支持类似 Rust 的枚举,根据平台自动优化的 Vec, 可以递归的 struct, 大数组零拷贝,流数据 (迭代器) 抽象,错误处理 (Result), 可取消的任务,并发控制,等。在 这里 查看所有特性。
  • 异步支持: Rust 代码永远不会阻塞 Flutter. 在 Flutter 的主隔离区 main isolate (或者说 thread) 中自然的调用 Rust 代码。
  • 轻量级: 这不是一个全面的框架,你可以自由的使用你喜欢的 Flutter 和 Rust 第三方库。例如,使用 Flutter 库(比如 MobX)进行状态管理更加优雅简单(相比于在 Rust 中实现); 使用 Rust 实现一个照片处理的算法更加快速和安全 (相比于在 Flutter 中实现).
  • 跨平台: 支持 Android, iOS, Windows, Linux, MacOS (Web coming soon)
  • 方便 & 易于代码审查: 这个库只是简单地模拟了人类编写的模板代码,一点也不神奇!如果你想让说服你自己(或你的团队)相信它是安全的, 没有多少代码可看。 (更多 safety concerns.)
  • 快速: 这个库只做了一个浅层次的包装(尽管功能丰富),没有 pritobuf 序列化的开销,因此高性能。(更多的 benchmarks 即将到来) (扔掉了像线程池这样的组件,使它更快)
  • 与纯 Dart 兼容: 尽管名字里包含了 Rust,这个库 100% 兼容 Pure Dart

💡 用户指南

请看 用户指南 for show-me-the-code, 教程, 特性 and much more.

📎 P.S. 方便的 Flutter 测试

如果您想在 Flutter 中方便地编写和调试测试,行为历史、时间回溯、屏幕截图、快速重新执行、视频录制、互动模式等功能,这里有我的另一个开源库:flutter_convenient_test.

✨ 贡献者

All Contributors

Thanks goes to these wonderful people (emoji key following all-contributors specification):


fzyzcjy

💻 📖 💡 🤔 🚧

Viet Dinh

💻 ⚠️ 📖

Joshua Wade

💻

Marcel

💻

rustui

📖

Michael Bryan

💻

bus710

📖

Sebastian Urban

💻

Daniel

💻

Kevin Li

💻 📖

Patrick Auernig

💻

Anton Lazarev

💻

Unoqwy

💻

Febrian Setianto

📖

syndim

💻

sagu

💻 📖

Ikko Ashimine

📖

alanlzhang

💻 📖

Sai Chaitanya

💻

Ares Andrew

📖

raphaelrobert

📖

thomas725

📖

Daniel Porteous (dport)

📖

Wouter Ensink

📖

老董

💻 📖

Lattice 0

💻 📖

orange soeur

📖

Rom's

💻 📖

Cupnfish

💻

More specifically, thanks for all these contributions:

  • Desdaemon: Support not only simple enums but also enums with fields which gets translated to native enum or freezed class in Dart. Support the Option type as nullable types in Dart. Support Vec of Strings type. Support comments in code. Add marker attributes for future usage. Add Linux and Windows support for with-flutter example, and make CI works for that. Avoid parameter collision. Overhaul the documentation and add several chapters to demonstrate configuring a Flutter+Rust project in all five platforms. Refactor command module. Precompiled binary CI workflow. Fix bugs.
  • SecondFlight: Allow structs and enums to be imported from other files within the crate by creating source graph. Auto-create relavent dir. Fix store_dart_post_cobject error with ffigen 6.0.
  • Unoqwy: Add struct mirrors, such that types in the external crates can be imported and used without redefining and copying.
  • antonok-edm: Avoid converting syn types to strings before parsing to improve code and be more robust.
  • lattice0: Support methods, such that Rust struct impls can be converted to Dart class methods. StreamSink at any argument.
  • sagudev: Make code generator a lib. Add error types. Depend on cbindgen. Fix LLVM paths. Update deps. Fix CI errors.
  • surban: Support unit return type. Skip unresolvable modules. Ignore prefer_const_constructors. Non-final Dart fields.
  • trobanga: Add support for [T;N] structs. Add usize support. Add a cmd argument. Separate dart tests.
  • Roms1383: Fix build_runner calling bug. Remove global ffigen dependency. Improve version check. Fix enum name-variant conflicts. Update CI. Code cleanup.
  • dbsxdbsx: Allow generating multiple Rust and Dart files.
  • AlienKevin: Add flutter example for macOS. Add doc for Android NDK bug.
  • alanlzhang: Add generation for Dart metadata.
  • efc-mw: Improve Windows encoding handling.
  • valeth: Rename callFfi's port.
  • Cupnfish: Allow multi mirror.
  • sccheruku: Prevent double-generating utility.
  • w-ensink: Improve doc. Fix CI. Refactor. Add tests.
  • Michael-F-Bryan: Detect broken bindings.
  • bus710: Add a case in troubleshooting.
  • Syndim: Add a bracket to box.
  • banool: Fix symbol-stripping doc.
  • TENX-S: Improve doc. Reproduce a bug.
  • raphaelrobert: Remove oudated doc.
  • thomas725: Improve doc.
  • juzi5201314: Improve doc.
  • feber: Fix doc link.
  • rustui: Fix a typo.
  • eltociear: Fix a typo.