# Rinf: Rust in Flutter

[![Pub Version](https://img.shields.io/pub/v/rinf)](https://pub.dev/packages/rinf)
[![Crate Version](https://img.shields.io/crates/v/rinf)](https://crates.io/crates/rinf)
[![GitHub Stars](https://img.shields.io/github/stars/cunarist/rinf)](https://github.com/cunarist/rinf/stargazers)
[![Test App](https://github.com/cunarist/rinf/actions/workflows/test_app.yaml/badge.svg)](https://github.com/cunarist/rinf/actions/workflows/test_app.yaml?query=branch%3Amain)
[![GitHub License](https://img.shields.io/github/license/cunarist/rinf)](https://github.com/cunarist/rinf/blob/main/LICENSE)

**Rust for native business logic, Flutter for flexible and beautiful GUI**

![Preview](https://github.com/cunarist/rinf/assets/66480156/5c9a7fb6-e566-4c4e-bd77-d72c1c064d6c)

Rinf is a framework for creating beautiful and performant cross-platform Rust apps by using Flutter as the UI layer. Simply add this framework to your app project, and you're all set to write Rust within Flutter!

## 📖 Documentation

Visit the [documentation](https://rinf.cunarist.com) to learn everything about using this framework. You can also explore the [example code](https://github.com/cunarist/rinf/tree/main/flutter_package/example).

## 🖥️ Platform Support

All platforms available with Flutter are [tested](https://github.com/cunarist/rinf/actions/workflows/test_app.yaml?query=branch%3Amain) and supported. Challenging build settings are automatically handled by this framework.

- ✅ Linux: Tested and supported
- ✅ Android: Tested and supported
- ✅ Windows: Tested and supported
- ✅ macOS: Tested and supported
- ✅ iOS: Tested and supported
- ✅ Web: Tested and supported

## 📞 Communication

Below is Rust code with business logic, and following that is Dart code with widgets.

```rust
MyMessage {
  current_number: 7,
  other_bool: true,
}
.send_signal_to_dart();
```

```dart
StreamBuilder(
  stream: MyMessage.rustSignalStream,
  builder: (context, snapshot) {
    final signalPack = snapshot.data;
    if (signalPack == null) {
      return Text('Nothing received yet');
    }
    final myMessage = signalPack.message;
    return Text(myMessage.currentNumber.toString());
  },
),
```

Of course, the opposite way from Dart to Rust is also possible in a similar manner.

All message classes and structs are generated by Rinf. You can define the message schema by using the derive attribute, making message passing between Dart and Rust very convenient.

## 🎁 Benefits

- **Truly easy**: It only takes about a minute or two to fully setup your app.
- **Efficient**: All communication occurs solely through native FFI. There are no webviews, web servers, hidden threads, or unnecessary memory copying that might cause performance overhead. This setup acts as a very thin wrapper around Dart and Rust.
- **Minimal**: This is not a bulky framework that requires you to install so many dependencies and use complicated CLI commands. Just focus on your code using your preferred Flutter and Rust libraries.
- **Event-driven**: The system reacts to events like user actions, messages, or signals. This allows for advanced concurrency, task cancellation, and non-blocking business logic.
- **Scalable**: Creating hundreds or even thousands of message APIs between Dart and Rust feels smooth and clean. Additionally, you have the flexibility to utilize any number of Rust library crates, perhaps including those you might have been working on.
- **High-level interface**: No messing with sensitive build files, no concerns about memory safety. Stay with Dart and Rust that you're familiar with.
- **Well maintained**: Our [automated workflows](https://github.com/cunarist/rinf/actions) including build tests are always kept passing, thanks to the main branch protection rule. Also, the number of external dependencies is kept as low as possible and documentations are thoughtfully organized.
- **Convenient debugging**: All the debugging functionalities are provided by default, without the need for dealing with browsers or mobile emulators. Also, the whole Rust logic is automatically restarted on Dart's hot restart.
- **Reliable**: Each component is supported by huge communities, ensuring a strong emphasis on future safety. You can easily assure your team of stability since this framework's underlying concept is fairly simple.

## 🐦 Why Use Flutter?

While Rust is a powerful language for high-performance native programming, its ecosystem for building graphical user interfaces is far from being mature. Though Rust already has some GUI frameworks, they don't compare to the extensive support and smooth development experience that Flutter provides. Flutter is the only framework that compiles to all six major platforms from a single codebase.

Flutter is a powerful and versatile framework that has gained immense popularity for building cross-platform applications with stunning user interfaces. It provides a declarative pattern, beautiful widgets, hot reload, convenient debugging tools, and dedicated packages for user interfaces right out of the box.

## 🦀 Why Use Rust?

While Dart excels as an amazing object-oriented language for GUI apps, its non-native garbage collection may not always meet demanding performance requirements, and it may lack advanced data manipulation packages. This is where Rust steps in, offering a remarkable speed advantage of up to [40 times faster](https://programming-language-benchmarks.vercel.app/dart-vs-rust) than Dart, alongside the ability to leverage multiple threads and various crates that get the job done.

Rust has garnered a devoted following, being [the most loved programming language](https://survey.stackoverflow.co/2022#section-most-loved-dreaded-and-wanted-programming-scripting-and-markup-languages) on Stack Overflow. Its native performance, thanks to the zero-cost abstraction philosophy, ensures high productivity. Many developers foresee Rust potentially replacing C++ in the future. Rust's simplicity, memory safety, superior performance in various scenarios, vibrant community, and robust tooling support contribute to its growing popularity.

## 👥 Contribution

If Rinf has been helpful, please consider giving a star to our [GitHub repository](https://github.com/cunarist/rinf) and a like to our [Pub package](https://pub.dev/packages/rinf). You can also support us by spreading the word and sharing this framework online.

We appreciate your contribution to the development of this project! We're always open to discussions and pull requests, so please do not hesitate to share your ideas or opinions on our GitHub repository.

[![GitHub contributors](https://contrib.rocks/image?repo=cunarist/rinf)](https://github.com/cunarist/rinf/graphs/contributors)
