Skip to main content

Directory structure (multi-file)

info

This page is about the directory generated by flutter_rust_bridge_codegen create/integrate. You are free to use whatever other methods to integrate Rust with Dart.

Overview

Though seemingly many files, it is pretty simple: "a standard Flutter app + a standard Rust crate + some glues to ignore". In short, write Flutter near lib/main.dart and Rust near rust/src/api/simple.rs.

Briefly speaking, the folders are:

  • /lib: Dart source code
    • 🐤 main.dart: Flutter app entrypoint code
    • src/rust: Auto generated glue, mirroring the whole Rust crate
  • /rust: Rust source code
    • 🦀 src/api/simple.rs: Write your Flutter-facing code anywhere within api folder
    • frb_generated.*.rs: Auto generated glue
  • /android, /ios, /linux, /macos, /web, /windows, /integration_test, /test, /test_driver: Other standard Flutter folders
  • /rust_builder: Ignore it (glue to build Rust with Flutter)

Details

Firstly, everything in this section only applies to the default template as a starter kit. You are surely free to customize everything, use your own template, etc, and flutter_rust_bridge continues to work well.

As mentioned above, a good starting point to write code is lib/main.dart and rust/src/api/simple.rs. Suppose we want to add more files:

  • For Dart, write anywhere in lib (the recommended place is inside lib/src).
  • For Rust, write anywhere in rust/src/api.

Remark: When adding a Rust file, remember to add it as a module in mod.rs. Otherwise, Rust (and flutter_rust_bridge) will act as if your file does not exist at all. For example, after creating rust/src/api/another.rs, we need to add a line pub mod another; inside rust/src/api/mod.rs.

Remarks

If you are interested: The rust_builder dummy package is likely to be able to be removed after the Dart "native assets" language feature is stabilized, which acts as a build hook similar to build.dart in the "native assets" feature.