Skip to content

Commit

Permalink
Merge pull request #453 from cunarist/shorten-docs
Browse files Browse the repository at this point in the history
Shorten docs
  • Loading branch information
temeddix authored Sep 27, 2024
2 parents 181a2d4 + 6dcacae commit 6e799af
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 52 deletions.
54 changes: 5 additions & 49 deletions documentation/docs/messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ There are special comments that you can mark messages with.

## 📢 Channels

`[RUST-SIGNAL]` generates a message channel from Rust to Dart.
`[RUST-SIGNAL]` generates a message channel from Rust to Dart. Use `[RUST-SIGNAL-BINARY]` to include binary data without the overhead of serialization.

```proto title="Protobuf"
// [RUST-SIGNAL]
Expand All @@ -24,39 +24,14 @@ StreamBuilder(
// Return an empty widget.
}
MyDataOutput message = rustSignal.message;
// Return a filled widget.
},
)
```

Use `[RUST-SIGNAL-BINARY]` to include binary data without the overhead of serialization.

```proto title="Protobuf"
// [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,
builder: (context, snapshot) {
final rustSignal = snapshot.data;
if (rustSignal == null) {
// Return an empty widget.
}
MyDataOutput message = rustSignal.message;
// Below requires `[RUST-SIGNAL-BINARY]`.
Uint8List binary = rustSignal.binary;
// Return a filled widget.
},
)
```

`[DART-SIGNAL]` generates a message channel from Dart to Rust.
`[DART-SIGNAL]` generates a message channel from Dart to Rust. Use `[DART-SIGNAL-BINARY]` to include binary data without the overhead of serialization.

```proto title="Protobuf"
// [DART-SIGNAL]
Expand All @@ -71,28 +46,9 @@ MyDataInput( ... ).sendSignalToRust();
let receiver = MyDataInput::get_dart_signal_receiver();
while let Some(dart_signal) = receiver.recv().await {
let message: MyDataInput = dart_signal.message;
// Custom Rust logic here
}
```

Use `[DART-SIGNAL-BINARY]` to include binary data without the overhead of serialization.

```proto title="Protobuf"
// [DART-SIGNAL-BINARY]
message MyDataInput { ... }
```

```dart title="Dart"
final binary = Uint8List(64);
MyDataInput( ... ).sendSignalToRust(binary);
```

```rust title="Rust"
let receiver = MyDataInput::get_dart_signal_receiver();
while let Some(dart_signal) = receiver.recv().await {
let message: MyDataInput = dart_signal.message;
// Below requires `[DART-SIGNAL-BINARY]`.
let binary: Vec<u8> = dart_signal.binary;
// Custom Rust logic here
// Custom Rust logic goes here.
}
```

Expand Down
4 changes: 2 additions & 2 deletions documentation/docs/state-management.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# State Management

This section provides a general guide on effectively managing application state while using Rinf. It is not an introduction to a specific feature of Rinf.
This section offers a general guide to managing application state effectively with Rinf, rather than introducing a specific Rinf feature.

Rinf performs best when the application logic is written entirely in Rust, with Flutter used solely for the GUI. In such cases, you might want to store the application state in Rust.
Rinf performs best when the application logic is written entirely in Rust, with Flutter used solely for the GUI. Given that, you might want to store the application state in Rust.

## 💥 Actor Model

Expand Down
5 changes: 4 additions & 1 deletion flutter_package/example/native/hub/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ use std::error::Error;
/// This `Result` type alias allows handling any error type
/// that implements the `Error` trait.
/// In practice, it is recommended to use custom solutions
/// or crates dedicated to error handling.
/// or crates like `anyhow` dedicated to error handling.
/// Building an app differs from writing a library, as apps
/// may encounter numerous error situations, which is why
/// a single, flexible error type is needed.
pub type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;

0 comments on commit 6e799af

Please sign in to comment.