diff --git a/.github/workflows/quality_control.yaml b/.github/workflows/quality_control.yaml index cc861e65..88b8d33b 100644 --- a/.github/workflows/quality_control.yaml +++ b/.github/workflows/quality_control.yaml @@ -23,6 +23,8 @@ jobs: code: name: dart-and-rust-code runs-on: ubuntu-latest + env: + RUSTFLAGS: -D warnings steps: - name: Checkout repository @@ -55,11 +57,10 @@ jobs: - name: Check for any errors run: | rustup target add wasm32-unknown-unknown - RUSTFLAGS="-D warnings" - cargo check - cargo check --release - cargo check --target wasm32-unknown-unknown - cargo check --target wasm32-unknown-unknown --release + cargo clippy + cargo clippy --release + cargo clippy --target wasm32-unknown-unknown + cargo clippy --target wasm32-unknown-unknown --release - name: Analyze code run: | diff --git a/flutter_ffi_plugin/lib/src/interface.dart b/flutter_ffi_plugin/lib/src/interface.dart index f7676b79..a3bc1c8a 100644 --- a/flutter_ffi_plugin/lib/src/interface.dart +++ b/flutter_ffi_plugin/lib/src/interface.dart @@ -10,7 +10,13 @@ typedef HandleRustSignal = void Function(int, Uint8List, Uint8List); /// This type is generic, and the message /// can be of any type declared in Protobuf. class RustSignal { - T message; - Uint8List binary; + /// The message instance of a class generated by Protobuf. + final T message; + + /// Binary data included in the signal. + /// This field is useful for sending custom bytes + /// without the overhead of serialization/deserialization. + final Uint8List binary; + RustSignal(this.message, this.binary); } diff --git a/rust_crate/src/interface.rs b/rust_crate/src/interface.rs index 27ba0420..cd18338d 100644 --- a/rust_crate/src/interface.rs +++ b/rust_crate/src/interface.rs @@ -10,7 +10,11 @@ use super::interface_web::*; /// This type is generic, and the message /// can be of any type declared in Protobuf. pub struct DartSignal { + /// The message instance of a struct generated by Protobuf. pub message: T, + /// Binary data included in the signal. + /// This field is useful for sending custom bytes + /// without the overhead of serialization/deserialization. pub binary: Vec, } diff --git a/rust_crate/src/interface_os.rs b/rust_crate/src/interface_os.rs index 395143ee..13ab06bc 100644 --- a/rust_crate/src/interface_os.rs +++ b/rust_crate/src/interface_os.rs @@ -1,6 +1,5 @@ use crate::debug_print; use allo_isolate::{IntoDart, Isolate, ZeroCopyBuffer}; -use backtrace::Backtrace; use os_thread_local::ThreadLocal; use std::cell::RefCell; use std::future::Future; @@ -35,7 +34,7 @@ where #[cfg(debug_assertions)] { std::panic::set_hook(Box::new(|panic_info| { - let backtrace = Backtrace::new(); + let backtrace = backtrace::Backtrace::new(); debug_print!("A panic occurred in Rust.\n{panic_info}\n{backtrace:?}"); })); } diff --git a/rust_crate/src/interface_web.rs b/rust_crate/src/interface_web.rs index ab34c49a..4a527995 100644 --- a/rust_crate/src/interface_web.rs +++ b/rust_crate/src/interface_web.rs @@ -1,4 +1,3 @@ -use crate::debug_print; use js_sys::Uint8Array; use std::future::Future; use wasm_bindgen::prelude::*; @@ -12,7 +11,7 @@ where #[cfg(debug_assertions)] { std::panic::set_hook(Box::new(|panic_info| { - debug_print!("A panic occurred in Rust.\n{panic_info}"); + crate::debug_print!("A panic occurred in Rust.\n{panic_info}"); })); } diff --git a/rust_crate/src/macros.rs b/rust_crate/src/macros.rs index dc2060d8..21c09d9f 100644 --- a/rust_crate/src/macros.rs +++ b/rust_crate/src/macros.rs @@ -1,5 +1,3 @@ -#![allow(clippy::crate_in_macro_def)] - #[macro_export] /// Writes the interface code /// needed to communicate with Dart. @@ -21,7 +19,7 @@ macro_rules! write_interface { #[cfg(not(target_family = "wasm"))] #[no_mangle] - pub extern "C" fn send_dart_signal_extern( + pub unsafe extern "C" fn send_dart_signal_extern( message_id: i64, message_pointer: *const u8, message_size: usize,