cunarist / rinf

Rust for native business logic, Flutter for flexible and beautiful GUI
MIT License
1.99k stars 72 forks source link

rinf template #220

Closed Noir-e closed 5 months ago

Noir-e commented 11 months ago

Report

Discussion about rinf template

Steps to Reproduce

Could you in the chapter "Applying Rust Template", if you can, please mention about rinf template -b or rinf template --bridge for clarity

Or maybe even add by default just rinf things without anything else, and add mandelbrot and etc by some argument like --example

It's just that these tutorial files make Rust part confusing, unless you deliberately go and check how to disable them

System Information

Please provide the output from the command below, using markdown codeblock syntax.

rustc --version
protoc --version
flutter doctor
PS C:\Users\user\rinf-test\flutter_ffi_plugin\example> rustc --version
rustc 1.73.0 (cc66ad468 2023-10-03)
PS C:\Users\user\rinf-test\flutter_ffi_plugin\example> protoc --version
libprotoc 25.0-rc2
PS C:\Users\user\rinf-test\flutter_ffi_plugin\example> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, 3.16.0-0.3.pre, on Microsoft Windows [Version 10.0.19045.3570], locale ru-RU)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.2.5)
[√] Android Studio (version 2021.1)
[√] Connected device (3 available)
[√] Network resources

! Doctor found issues in 1 category.
temeddix commented 11 months ago

That's an interesting idea. Indeed removing all the examples from the template would be a nice place to start. I will keep this issue open until there's a PR or I have time to implement that feature :)

bookshiyi commented 11 months ago

How do you think that separate to two command args like : rinf sample used for understand how it work and rinf template used for start to develop.

temeddix commented 11 months ago

Yeah, that would be a good idea :)

In my opinion, rinf template can provide only the base template, while rinf template --sample provides the full sample code, when we copy those template files.

I already have an idea on how it could work. We could possibly add comments on line or lines that should be excluded in the template, unless --sample option is included.

// native/hub/src/lib.rs

use bridge::respond_to_dart;
use tokio_with_wasm::tokio;
use with_request::handle_request;

mod bridge;
mod messages;
mod sample_functions;  # SAMPLE
mod with_request;

/// This `hub` crate is the entry point for the Rust logic.
/// Always use non-blocking async functions such as `tokio::fs::File::open`.
async fn main() {
    // This is `tokio::sync::mpsc::Reciver` that receives the requests from Dart.
    let mut request_receiver = bridge::get_request_receiver();
    // Repeat `tokio::spawn` anywhere in your code
    // if more concurrent tasks are needed.
    tokio::spawn(sample_functions::stream_mandelbrot());  # SAMPLE
    tokio::spawn(sample_functions::run_debug_tests());  # SAMPLE
    while let Some(request_unique) = request_receiver.recv().await {
        tokio::spawn(async {
            let response_unique = handle_request(request_unique).await;
            respond_to_dart(response_unique);
        });
    }
}

And I would implement this idea once I have time, though I think it would take a few days, or weeks for me to be free. This implementation doesn't look too hard. Meanwhile, PR for this is welcome :)