Skip to content

Commit

Permalink
Merge pull request #226 from bookshiyi/Update-message-code-generation…
Browse files Browse the repository at this point in the history
…-doc

Update message code generation section documents
  • Loading branch information
temeddix authored Nov 23, 2023
2 parents 3430af9 + f0aef33 commit 4b97e29
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
8 changes: 2 additions & 6 deletions documentation/docs/rust-resource-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ Each `.proto` file located in `./messages` and its subfolders is treated as a Ru

Each Rust resource will be assigned a unique `ID` on code generation, which is inserted into the `resource` field of `RustRequest` and `RustSignal` to distinguish which Rust resource that the message is trying to talk about.

When you generate message code using the `rinf message` command, the resulting Dart and Rust modules' names and subpaths will precisely correspond to those of the `.proto` files.

- `./messages`: `.proto` input files
- `./lib/messages`: `.dart` output files
- `./native/hub/src/messages`: `.rs` output files

This framework follows the RESTful API pattern, allowing for the definition of 9 possible message combinations within each `.proto` file like below. However, it's totally acceptable to create other message types as well.

```proto
Expand All @@ -26,4 +20,6 @@ message DeleteResponse { ... }
message StateSignal { ... }
```

For more details about generating message code, refer to the [message code section](writing-code.md#message-code-generation).

> We highly recommend NOT version-controlling the generated message code. This framework writes folders containing the generated code to `.gitignore` when applying the template to prevent unnecessarily bloated Git history. Usually, only version-controlling `.proto` files is enough.
6 changes: 6 additions & 0 deletions documentation/docs/shorthand-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ After you've installed the `rinf` executable, you can use this tool to execute a
rinf ...
```

If you're curious about all the available commands, use the `--help` argument.

```bash
rinf --help
```

> All the commands of this framework can originally be executed with `dart run rinf ...`. However, this is quite long and cumbersome to write over and over again. That's why this framework provides a shorthand command executable.
22 changes: 20 additions & 2 deletions documentation/docs/writing-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,32 @@ final rustResponse = await requestToRust(

While Rinf's API system may resemble that of web development, it relies only on native FFI for communication. It does NOT use any web protocols, hidden threads, and unnecessary memory copying to prevent any performance overhead.

## ⌛ Continuous Message Generation
## 📦 Message Code Generation

If you add the optional argument `-w` or `--watch` to the `rinf message` command, the message code will automatically generated when `.proto` files are modified. When you add this argument, the command will not exit on its own.
### Path

When you generate message code using the `rinf message` command, the resulting Dart and Rust modules' names and subpaths will precisely correspond to those of the `.proto` files.

- `./messages` : The `.proto` files under here and its subdirectories will be used to generating message code.
- `./lib/messages` : The generated Dart code will be placed here.
- `./native/hub/src/messages` : The generated Rust code will be placed here.

### Continuous Message Generation

If you add the optional argument `-w` or `--watch` to the `rinf message` command, the message code will automatically generated when `.proto` files are modified. If you add this argument, the command will not exit on its own.

```bash
rinf message --watch
```

Currently, recursive watching is not supported on all platforms.

| | While watching | One-time gen |
| ------- | -------------- | ------------ |
| Linux |||
| macOS |||
| Windows |||

## 🖨️ Printing for Debugging

You might be used to `println!` macro in Rust. However, using that macro isn't a very good idea in our apps made with Flutter and Rust because `println!` outputs cannot be seen on the web and mobile emulators.
Expand Down

0 comments on commit 4b97e29

Please sign in to comment.