Closed erlangparasu closed 8 months ago
Thanks for the idea :)
This will be a good addition, yes. I will try to apply it when I have time later. Meanwhile, any kind of PR is welcome!
For now, I can suggest using the lazy_static
Rust crate for state management.
Hey @temeddix maybe also consider using OnceLock
which is in the standard lib now. In practice you end up doing a little more to make things work, like making a helper function but it works quite well.
I'm doing some diving on how best to make cross-platform apps in Rust (or something other the duopoly of Swift/Kotlin, essentially) and rinf
looks great but state management being in Dart does worry me a little bit.
It occurs to me to move the state completely to Rust (and thus every call to modify any state must immediately move to Rust), but it wasn't clear the expected pattern was -- is there even a point in declaring any meaningful Dart state if someone opts to create/manage state only in Rust?
I made a toy app for doing something similar
enum AppState
{
InputScreen (...)
ResultScreen(...)
}
enum AppAction
{
AddInput(...)
Calculate
}
the rust requests respond with an empty unit. but it also sends the latest state down the stream
the app has no state, it's a stream builder
the state on rust end is stored in OnceCell Mutex
OnceCell
and OnceLock
look like a good choice, given that it's now part of the standard library.
Would anyone mind sharing one's repository link here, so we can share the whold idea of how the app would look like?
For most GUI apps, 'widget state' is not recommended to be managed by the backend logic, but the core state might be handled by Rust. If anyone is open to sharing one's repository, please let me know!
https://github.com/ryanhossain9797/proportional_cost_splitter_app
Here's mine if you want to take a look
Is there a documentation link yet?
Not really, it's just that the global state variable is now included in the example code(native/hub/src/sample_functions.rs
).
However it would be nice to also add the state management in the docs. Let's keep this open until I write the state+stream guide in the docs as well :)
May I ask, does #301 look okay? @erlangparasu
@temeddix Thanks a lot!
Report
please provide example stream with state class (for storing state data) currently only example with single function it would be great if there was an example for use with a class as storing state
https://github.com/cunarist/rinf/issues/230