Skip to content

Commit

Permalink
Add documentation and example
Browse files Browse the repository at this point in the history
  • Loading branch information
temeddix committed Jul 27, 2024
1 parent 5c47b7c commit d90b655
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
37 changes: 22 additions & 15 deletions documentation/docs/messaging.md
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -25,17 +29,18 @@ 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"
// [RINF:RUST-SIGNAL-BINARY]
message MyDataOutput { ... }
```

```rust title="Rust"
let binary: Vec<u8> = vec![0; 64];
MyDataOutput { ... }.send_signal_to_dart(binary);
```

```dart title="Dart"
StreamBuilder(
stream: MyDataOutput.rustSignalStream,
Expand All @@ -51,14 +56,7 @@ StreamBuilder(
)
```

```rust title="Rust"
let binary: Vec<u8> = 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]
Expand Down Expand Up @@ -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 { ... }
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
syntax = "proto3";
package enum_and_oneof;
package sample_file;

enum Kind {
one = 0;
Expand All @@ -23,3 +23,8 @@ message SampleOutput {
int32 age = 3;
}
}

// [RINF:RUST-ATTRIBUTE(#[derive(Copy)])]
message WithRustAttribute {
bool dummy = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d90b655

Please sign in to comment.