Skip to content

Docs/examples/fixes to make rust-async, threadpool optional #2253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aran opened this issue Aug 21, 2024 · 5 comments · May be fixed by #2723
Closed

Docs/examples/fixes to make rust-async, threadpool optional #2253

aran opened this issue Aug 21, 2024 · 5 comments · May be fixed by #2723
Labels
enhancement New feature or request

Comments

@aran
Copy link
Contributor

aran commented Aug 21, 2024

Is your feature request related to a problem? Please describe.
From website/docs/guides/custom/rust/feature-flags.md it may be possible to remove unused features from the FRB import.

In my project at least, in disabling threadpool, the default generated executor seems to break compilation:

error[E0599]: the method `wrap_sync` exists for struct `FLUTTER_RUST_BRIDGE_HANDLER`, but its trait bounds were not satisfied
    --> .../frb_generated.rs:4454:33
     |
45   | flutter_rust_bridge::frb_generated_default_handler!();
     | ----------------------------------------------------- method `wrap_sync` not found for this struct
...
4454 |     FLUTTER_RUST_BRIDGE_HANDLER.wrap_sync::<flutter_rust_bridge::for_generated::SseCodec, _>(
     |     ----------------------------^^^^^^^^^ method cannot be called on `FLUTTER_RUST_BRIDGE_HANDLER` due to unsatisfied trait bounds
     |
    ::: /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge-2.3.0/src/handler/implementation/handler.rs:42:1
     |
42   | pub struct SimpleHandler<E: Executor, EL: ErrorListener> {
     | -------------------------------------------------------- doesn't satisfy `_: Handler`
     |
    ::: /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge-2.3.0/src/handler/implementation/executor.rs:23:1
     |
23   | pub struct SimpleExecutor<EL: ErrorListener, TP: BaseThreadPool, AR: BaseAsyncRuntime> {
     | -------------------------------------------------------------------------------------- doesn't satisfy `_: Executor`
     |
     = note: the following trait bounds were not satisfied:
             `SimpleExecutor<NoOpErrorListener, &LocalKey<SimpleThreadPool>, SimpleAsyncRuntime>: Executor`
             which is required by `SimpleHandler<SimpleExecutor<NoOpErrorListener, &LocalKey<SimpleThreadPool>, SimpleAsyncRuntime>, NoOpErrorListener>: Handler`
     = help: items from traits can only be used if the trait is implemented and in scope
     = note: the following trait defines an item `wrap_sync`, perhaps you need to implement it:
             candidate #1: `Handler`

In disabling rust-async—I am trying to use all methods as #[frb(sync)], but it's possible I've missed something—I see errors due to Lockable, RustAutoOpaqueInner, LockableOrderInfo and a few others. The RustAutoOpaqueInner errors are tied to types that I have pub use imported, frb(mirror(, and #[frb(external)]. E.g.:

error[E0412]: cannot find type `RustAutoOpaqueInner` in module `flutter_rust_bridge::for_generated`
   --> .../rust/src/frb_generated.rs:197:53
    |
197 |                 flutter_rust_bridge::for_generated::RustAutoOpaqueInner<MyType>,
    |                                                     ^^^^^^^^^^^^^^^^^^^ not found in `flutter_rust_bridge::for_generated`
    |
note: found an item that was configured out
   --> /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge-2.3.0/src/for_generated/mod.rs:62:42
    |
62  | pub use crate::rust_auto_opaque::{inner::RustAutoOpaqueInner, RustAutoOpaqueBase};
    |                                          ^^^^^^^^^^^^^^^^^^^
note: the item is gated behind the `rust-async` feature
   --> /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge-2.3.0/src/for_generated/mod.rs:61:7
    |
61  | #[cfg(feature = "rust-async")]
    |       ^^^^^^^^^^^^^^^^^^^^^^

Describe the solution you'd like
Not sure. I am already using, or intending to use, all sync methods for thread safety on wasm platform. I don't think I am using the threadpools. I would be looking for either documentation, example code, or code-generator errors to lead me to what I've done wrong here.

Describe alternatives you've considered
N/A

@aran aran added the enhancement New feature or request label Aug 21, 2024
@fzyzcjy
Copy link
Owner

fzyzcjy commented Aug 22, 2024

Firstly, I wonder why do you want to disable those features? IIRC Rust does a lot of optimizations and will eliminate dead code if you do not use a feature automatically.

Secondly, for thread pools: #2215 may be related if you want to disable it because of the web things.

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Aug 22, 2024
@aran
Copy link
Contributor Author

aran commented Aug 22, 2024

My thinking was, I'm not (supposed to be) using them. If I were to use the threadpool accidentally, that would be a bug. I do see some extra activity in web console in setting up the service workers which I assume is due to the threadpool.

For async, just looking for opportunities to cut down surface area.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Aug 22, 2024

I see, then #2215 may be useful for thread pool thing. For async, looks like e.g. opaque types uses tokio rwlock currently, so it requires the tokio dependency, and thus the flag async.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Sep 11, 2024

Close since that issue is closed. But feel free to reopen this issue if you have any questions!

@fzyzcjy fzyzcjy closed this as completed Sep 11, 2024
@fzyzcjy fzyzcjy removed the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Sep 11, 2024
Copy link
Contributor

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants