-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: trdthg <trdthg@outlook.com>
- Loading branch information
Showing
10 changed files
with
111 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
# Features | ||
# 特性 | ||
|
||
In this chapter, we are going to demonstrate the features. Please use the menu bar at the left / left-top of the page to navigate. | ||
这一章,我们将展示该库的各个特性。请使用左侧/左上的菜单栏切换页面。 | ||
|
||
## Prelogue | ||
## 序言 | ||
|
||
### What this library is and is not | ||
### 这个库是什么? | ||
|
||
This library is nothing but a code generator that helps your Flutter/Dart functions call Rust functions. It only generates some boilerplate code that you will manually write down otherwise. Moreover, we have provided detailed tutorials for you to play with examples, set up brand new apps, and integrate with existing apps. | ||
这个库只是一个代码生成器,帮助你的 Flutter/Dart 函数调用 Rust | ||
函数。它只会生成一些模板代码,代替了手工编写。此外,我们还为您提供了详细的教程,让您可以尝试实例,创建新的应用程序,并与现有的应用程序集成。 | ||
|
||
Of course, you may still need to have some basic familiarity with Flutter/Dart, Rust, and its [ffi](https://flutter.dev/docs/development/platform-integration/c-interop). | ||
当然,你仍然需要对 Flutter/Dart,Rust 以及 | ||
[ffi](https://flutter.dev/docs/development/platform-integration/c-interop). | ||
有一些基本的了解。 | ||
|
||
### Full examples | ||
### 完整实例 | ||
|
||
If you want to look at a lot of examples - I have to warn you, really too many - have a look at [pure_dart's api.rs](https://github.com/fzyzcjy/flutter_rust_bridge/blob/master/frb_example/pure_dart/rust/src/api.rs). It contains all tests for this library. | ||
|
||
In addition, when you are quite familiar with the basic example, you can then take a look at [pure_dart_multi](https://github.com/fzyzcjy/flutter_rust_bridge/tree/master/frb_example/pure_dart_multi/rust/src). This example contains multiple blocks of APIs instead of one, which is quite useful for complex projects. | ||
如果你想看一些例子 - 我要提前警告你,示例代码真的非常多 - | ||
[pure_dart's api.rs](https://github.com/fzyzcjy/flutter_rust_bridge/blob/master/frb_example/pure_dart/rust/src/api.rs). | ||
里面包含了对该库的所有测试。 | ||
|
||
此外,当你对基本的例子已经熟悉后,你就可以看一下 | ||
[pure_dart_multi](https://github.com/fzyzcjy/flutter_rust_bridge/tree/master/frb_example/pure_dart_multi/rust/src). | ||
这个例子包含多个 API 模块。对于复杂的项目来说是相当有用的。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Language translations | ||
# 语言间转换 | ||
|
||
In this section, we will show how various language features are translated between Rust and Dart. | ||
这一部分我们将展示 Rust 和 Dart 语言间的特性是如何转换。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
# Return Types | ||
# 返回值类型 | ||
|
||
The return type can be either `anyhow::Result<YourType>`, or `YourType` directly. | ||
返回值类型可以是 `anyhow::Result<YourType>`, 或者直接是你的类型 `YourType` . | ||
|
||
## Example | ||
## 示例 | ||
|
||
```rust,noplayground | ||
pub fn f(a: i32, b: i32) -> i32 { a + b } | ||
pub fn g(a: i32, b: i32) -> anyhow::Result<i32> { Ok(a + b) } | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
# Vec and array | ||
# Vec and 数组 | ||
|
||
## `Vec<u8>`, `Vec<i8>`, ... | ||
|
||
In Dart, when you want to express a long byte array such as a big image or some binary blob, people normally use `Uint8List` instead of `List<int>` since the former is much performant. `flutter_rust_bridge` takes this into consideration for you. When you have `Vec<u8>` (or `Vec<i8>`, or `Vec<i32>`, etc), it will be translated it into `Uint8List` or its friends. | ||
在 Dart 中,当你想表达一个长字节数组,例如大图片或一些二进制 blob,人们通常会使用 `Uint8List` 而不是 | ||
`List<int>`,因为前者的性能更好。 | ||
|
||
`flutter_rust_bridge` 也为你考虑到了这一点。当你使用到 `Vec<u8>`(或 | ||
`Vec<i8>`,`Vec<i32>`,等)时,它将被翻译成 `Uint8List` 或其它类似的结构。 | ||
|
||
## `Vec<T>` | ||
|
||
When you have normal `Vec<T>` for `T` types other than `u8`, `i8` etc, it will be converted to normal `List<T>`. | ||
当你使用 `Vec<T>`,并且 T 是 `u8`、`i8` 等以外的类型时,它将被转换成正常的 `List<T>`。 | ||
|
||
## `[T; N]` | ||
|
||
Since Dart does not have special treatment for static-sized arrays, it is converted to `List<T>` as well. | ||
由于 Dart 没有对静态大小的数组进行特殊处理,所以它也会被转换为 `List<T>`。 | ||
|
||
## Example | ||
## 例子 | ||
|
||
```rust,noplayground | ||
pub fn draw_tree(tree: Vec<TreeNode>) -> Vec<u8> { ... } | ||
``` | ||
|
||
Becomes: | ||
转换为: | ||
|
||
```Dart | ||
Future<Uint8List> drawTree({required List<TreeNode> tree}); | ||
``` | ||
|
||
Remark: If you are curious about `Future`, have a look at [this](async_dart.md). | ||
|
||
注意:如果你对 `Future` 感兴趣,请看 [这里](async_dart.md). |