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.25k stars 299 forks source link

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

Closed 107295472 closed 1 week ago

107295472 commented 1 week 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 1 week 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 1 week 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 1 week ago

image

fzyzcjy commented 1 week ago

Happy to see it is solved (closed)!