Flutter Rust Bridge는 Flutter/Dart와 Rust 간의 바인딩을 생성하는 강력하고 원활한 도구로, 고성능 네이티브 코드 통합을 가능하게 합니다. 최소한의 봐일러플레이트로 다중 언어 간 통신을 단순화하며, 모바일, 웹, 데스크톱을 포함한 모든 주요 플랫폼을 지원합니다. async/await 지원, 타입 안정성, 자동 코드 생성과 같은 풍부한 기능을 제공하여, 복잡한 수동 인터페이스 없이도 Flutter 앱 내에서 Rust의 속도와 신뢰성을 활용하고자 하는 개발자에게 이상적입니다.
사용 사례
고성능 루스트 라이브러리를 Flutter 앱에 통합하기
안전하고 빠른 암호화 모듈 구축
Rust 백엔드를 사용한 실시간 데이터 처리 활성화
플랫폼에 관계없는 네이티브 확장 만들기
계산 집약적 작업 최적화
주요 기능
자동 바인딩 생성
크로스 플랫폼 지원 (Android, iOS, Web, macOS, Windows, Linux)
Async/await 호환성
형 안전한 상호 운용성
최소한의 보일러플레이트
복잡한 데이터 유형 지원
적합한 대상
성능이 중요한 로직에 Rust를 사용하는 개발자
네이티브 속도가 필요한 하이브리드 앱을 개발하는 팀
보안 또는 저수준 시스템 접근이 필요한 프로젝트
무결점 Dart-Rust 통합을 찾는 엔지니어
고려 사항
Rust 프로그래밍에 대한 숙련도가 필요합니다
초기 설정은 Rust 정의에서 코드를 생성하는 것을 포함합니다
코드 생성으로 인해 빌드 시간이 증가할 수 있습니다
빠른 프로토타이핑 요구 사항보다 성능이 우선되는 프로젝트에 가장 적합
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
flutter_rust_bridge v2: Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
What's new in V2
Tap to expand
From 1.x to 2.0.0-dev.0:
Rapid setup: Only a one-liner command to integrate into your project.
Arbitrary types: Use arbitrary Rust and Dart types without manual intervention, even if they are not serializable or non-clone (previously need some manual intervention).
Async Rust: Support asynchronous Rust (async fn), in addition to sync Rust / async Dart / sync Dart.
Rust call Dart: Allow Rust to call Dart functions (previously only allow Dart to call Rust).
Support whole folders as inputs: Previously only support one single file (e.g. api.rs).
Use libraries/tools in Flutter/Rust: All existing libraries, Flutter debuggers, ... Nothing to stop you from using them.
From 2.0.0-dev.0 to 2.0.0:
Parsing third-party packages: Scan and use existing Rust packages in Dart (experimental).
Lifetimes: Support returning types with lifetime specifiers (experimental).
Traits: Support traits as base classes and trait objects.
New codec: A new codec, SSE, which is several times faster under some workloads.
Others (>200 PRs): Auto and manual accessors, object proxies, user-defined serializers, developer experience, deadlock-free auto locking, Rust initializers, included batteries, renaming and ignoring, improving streams, more types, ...
Please visit this page for more information and update guide.
🍀 What's this?
Just write down normal Rust code (even with arbitrary types, closure, &mut, async, traits, etc)
And call it from Flutter, as if Rust code is normal Flutter code
The bridge will generate all glues in between
📚 Quickstart
Create a working Flutter + Rust app and see it live, by running:
cargo install flutter_rust_bridge_codegen && flutter_rust_bridge_codegen create my_app && cd my_app && flutter run
Expand optional steps
(Optional) Edit rust/src/api/simple.rs (e.g. Hello -> Hi), then see the change by:
flutter_rust_bridge_codegen generate && flutter run
For more elaborated quickstart, please visit this page.
(Tap to expand) Rapid setup, Write your code naturally, Use libraries/tools in Flutter/Rust, Battery included
Rapid setup: Only a one-liner command to integrate into your project.
Write your code naturally: Use your intuition and write the code you want. The bridge understands many advanced grammars (see below), allowing seamless calling Rust from Dart.
Use libraries/tools in Flutter/Rust: All existing libraries, Flutter debuggers, ... Nothing to stop you from using them.
Battery included: Even small things like logging and enable backtraces are configured in the starter kit.
Arbitrary types: Use arbitrary Rust and Dart types without manual intervention, even if they are not serializable or non-clone.
Async & sync x Rust & Dart: Multi modes for various needs - Async Dart to avoid blocking the main thread, sync Dart for places needed (e.g. Widget.build); async Rust for IO bound tasks, thread pools for CPU-heavy computations.
Two-way road: Not only can Dart call Rust - Rust can also call Dart.
Auto-translatable types: Lots of types can be further translated to Dart native types, e.g. complex enums and structs, zero-copy big arrays, errors (Result), and Streams (iterator).
Parsing third-party packages: Scan and use existing Rust packages in Dart (experimental).
Auto safety: Focus on your code, and forget memory safety, malloc/free, or undefined behavior completely.
Customizable & bare-metal mode: Provide sensible defaults, but everything (loader, handler, ...) can be customized. You can even throw all away and only use the bare minimum calling.
Cross-platform: Support Android, iOS, Windows, Linux, MacOS, and Web (both JavaScript and WebAssembly).
Other features, e.g. support whole folders as input, pure-Dart compatible, instance and static methods, ...
4. Reliability
(Tap to expand) Solid CI, Used by many people, Easy to review, Fast, Hackable, Ask questions
Solid CI: Valgrind & sanitizers (ASAN/MSAN/LSAN) for memory/UB-related bugs, testing per platform per mode, benchmarking, test coverage, post-release, etc, all guaranteed by CI.
Used by many people: See here for an incomplete list.
Easy to code-review & convince yourself: This package simply simulates how humans write boilerplate code. If you want to convince yourself (or your team) that it is safe, there is not much code to track.
Fast: It is only a thin (though feature-rich) wrapper, benchmarked on CI, and even has multiple codecs for best performance under different workloads.
Hackable: If (for whatever reason) you want to hack the source, there are contributor guides, code is modular, and the execution logic is intuitive.
Ask questions: Feel free to ask questions in the issue tracker, and I usually reply within hours (if not sleeping).
Why Flutter + Rust?
Tap to expand
Firstly, super briefly introduce each component (you can find much more in a lot of blogs and posts):
"The most popular cross-platform mobile SDK" (by StackOverflow [1][2]).
Rust: Highly efficient and performant, reliable, productive.
"The most desired programming language" for 8 years (by StackOverflow and GitHub [1][2]).
Typical scenarios to combine them include:
UI framework for Rust: When you want a UI framework for your Rust system.
Use arbitrary Rust libraries in Flutter: When the desired functionality only has a library in Rust, not Dart (Flutter).
Need high-performance code for Flutter: Rust makes it easy and performant to write multi-thread code, algorithms, data-intensive operations, SIMD code, etc.
📎 P.S. Achieve ~60 FPS, no matter how janky the Flutter app was due to build/layout
Here is my other open-source library :) https://github.com/fzyzcjy/flutter_smooth.
✨ Acknowledgments and contributors
Firstly, I want to sincerely thank Dart, Flutter and Rust (alphabetical order). Dart provides a solid foundation for productive UI development, Flutter enables developers to make cross-platform apps with ease, and Rust empowers everyone to build reliable and efficient software. Without the languages and frameworks, this bridge connects absolutely nothing. Besides, I also want to express my thanks for conferring the official Flutter Favorite honor to the package. In addition, I also want to say thanks to the Dart, Flutter and Rust team members as well as community members, who have helped me during the development of flutter_rust_bridge by valuable discussions, insights, and actions.
Secondly, thanks goes to these wonderful contributors (emoji key following all-contributors specification):
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 sealed freezed class in Dart. Support the Option type as nullable types in Dart. Support Vec of Strings type. Support tuple 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. Add support for the Web platform, parallel to the existing mobile/desktop platforms, via WASM and JavaScript as intermediate values. GitHub retry actions. Implement draft of opaque types. Refactor Boxed and Option. Impl list of dates and optionals. Parameter defaults. Refactor CLI. Refactor codegen errors. Refactor for performance.
rogurotus: Add Rust opaque types, enabling arbitrary Rust structs to be used as opaque Dart objects by generating wrappers and raw Arc pointers. Also add Dart opaque types, allowing to use any Dart objects in Rust code. Extend SyncReturn for more types. Fix generation bug. Fix SyncReturn. Migrate to dart-sys. Update CI. Fix linters. Fix SyncReturn bug.
ngasull: Make sync mode support whatever types that classical async mode supports. Bump sdk.
SecondFlight: Allow structs and enums to be imported from other files within the crate by creating source graph. Auto-create relevant dir. Fix store_dart_post_cobject error with ffigen 6.0.
lattice0: Implement hierarchy of exceptions. Support methods, such that Rust struct impls can be converted to Dart class methods. StreamSink at any argument.
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.
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.
Roms1383: Fix build_runner calling bug. Remove global ffigen dependency. Improve version check. Fix enum name-variant conflicts. Support Chrono date time and UUID types. Migrate to Rust 1.64 workspace. Update and refactor CI. Update header comments. Code cleanup.
GregoryConrad: Add doc to setup frb inside a Dart/Flutter library.
huang12zheng: Support type aliases and nested ones. Tweak code generation. Fix rust_build_and_test on Mac. Improve CI logic and cache. Remove bridge field in model.
trobanga: Add support for [T;N] structs. Add usize support. Add a cmd argument. Separate dart tests. Fix fallible list case. Fix test compile. Fix Result + RustAutoOpaque.
MnlPhlp: Support macros and will auto expand. Allow mirror types in streams.