diff --git a/documentation/docs/messaging.md b/documentation/docs/messaging.md index 67fd07058..d181242d9 100644 --- a/documentation/docs/messaging.md +++ b/documentation/docs/messaging.md @@ -1,16 +1,20 @@ # Messaging -There are 2 types of special comments that you can mark messages with. +There are special comments that you can mark messages with. -## 📢 Rust Signal +## 📢 Channels -`[RINF:RUST-SIGNAL]` generates a channel from Rust to Dart. +`[RINF:RUST-SIGNAL]` generates a message channel from Rust to Dart. ```proto title="Protobuf" // [RINF:RUST-SIGNAL] message MyDataOutput { ... } ``` +```rust title="Rust" +MyDataOutput { ... }.send_signal_to_dart(); +``` + ```dart title="Dart" StreamBuilder( stream: MyDataOutput.rustSignalStream, @@ -25,10 +29,6 @@ StreamBuilder( ) ``` -```rust title="Rust" -MyDataOutput { ... }.send_signal_to_dart(); -``` - Use `[RINF:RUST-SIGNAL-BINARY]` to include binary data without the overhead of serialization. ```proto title="Protobuf" @@ -36,6 +36,11 @@ Use `[RINF:RUST-SIGNAL-BINARY]` to include binary data without the overhead of s message MyDataOutput { ... } ``` +```rust title="Rust" +let binary: Vec = vec![0; 64]; +MyDataOutput { ... }.send_signal_to_dart(binary); +``` + ```dart title="Dart" StreamBuilder( stream: MyDataOutput.rustSignalStream, @@ -51,14 +56,7 @@ StreamBuilder( ) ``` -```rust title="Rust" -let binary: Vec = vec![0; 64]; -MyDataOutput { ... }.send_signal_to_dart(binary); -``` - -## 📭 Dart Signal - -`[RINF:DART-SIGNAL]` generates a channel from Dart to Rust. +`[RINF:DART-SIGNAL]` generates a message channel from Dart to Rust. ```proto title="Protobuf" // [RINF:DART-SIGNAL] @@ -97,3 +95,12 @@ while let Some(dart_signal) = receiver.recv().await { // Custom Rust logic here } ``` + +## 🔖 Attributes + +`[RINF:RUST-ATTRIBUTE(...)]` writes an attribute above the generated message struct in Rust. This is useful when you want to automatically implement a trait for the message struct in Rust. + +```proto title="Protobuf" +// [RINF:RUST-ATTRIBUTE(#[derive(Copy)])] +message MyDataInput { ... } +``` diff --git a/flutter_ffi_plugin/example/messages/sample_folder/enum_and_oneof.proto b/flutter_ffi_plugin/example/messages/sample_folder/sample_file.proto similarity index 73% rename from flutter_ffi_plugin/example/messages/sample_folder/enum_and_oneof.proto rename to flutter_ffi_plugin/example/messages/sample_folder/sample_file.proto index 354256817..c0a5adf23 100644 --- a/flutter_ffi_plugin/example/messages/sample_folder/enum_and_oneof.proto +++ b/flutter_ffi_plugin/example/messages/sample_folder/sample_file.proto @@ -1,5 +1,5 @@ syntax = "proto3"; -package enum_and_oneof; +package sample_file; enum Kind { one = 0; @@ -23,3 +23,8 @@ message SampleOutput { int32 age = 3; } } + +// [RINF:RUST-ATTRIBUTE(#[derive(Copy)])] +message WithRustAttribute { + bool dummy = 1; +} diff --git a/flutter_ffi_plugin/example/native/hub/src/sample_functions.rs b/flutter_ffi_plugin/example/native/hub/src/sample_functions.rs index 44e3713c5..eaa8f4d76 100755 --- a/flutter_ffi_plugin/example/native/hub/src/sample_functions.rs +++ b/flutter_ffi_plugin/example/native/hub/src/sample_functions.rs @@ -109,7 +109,7 @@ pub async fn stream_fractal() { // A dummy function that uses sample messages to eliminate warnings. #[allow(dead_code)] async fn use_messages() -> Result<()> { - use messages::sample_folder::enum_and_oneof::*; + use messages::sample_folder::sample_file::*; let _ = SampleInput::get_dart_signal_receiver()?; SampleOutput { kind: 3,