fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.29k stars 301 forks source link

Changing the flow from 1 to 2, what is wrong #2374

Closed 107295472 closed 3 weeks ago

107295472 commented 3 weeks ago
lazy_static! {
    static ref SEND_TO_DART_LOGGER_STREAM_SINK: RwLock<Option<StreamSink<ResMsg>>> =
        RwLock::new(None);
}
fn cmd_msg(s: ResMsg) {
    if let Some(sink) = &*SEND_TO_DART_LOGGER_STREAM_SINK.read() {
        sink.add(s);
    }
}
pub fn create_msg(sink: StreamSink<ResMsg>) {
    let mut guard = SEND_TO_DART_LOGGER_STREAM_SINK.write();

    *guard = Some(sink);
}

this error originates in the macro $crate::frb_generated_stream_sink which comes from the expansion of the macro flutter_rust_bridge::frb_generated_boilerplate (in Nightly builds, run with -Z macro-backtrace for more info) image

fzyzcjy commented 3 weeks ago

Hi, could you please check your ResMsg type? For example, if it is not of lifetime static, then it will not work, because stream items needs to live arbitrarily long.

107295472 commented 3 weeks ago
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResMsg<'a> {
    pub percentage: f32,
    pub count: i32,
    pub message: &'a str,
    pub code: i32,
}
107295472 commented 3 weeks ago

image

fzyzcjy commented 3 weeks ago

Happy to see it is solved (closed)!

github-actions[bot] commented 1 week ago

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.