Skip to content

Commit 131f818

Browse files
authored
Merge pull request fzyzcjy#2599 from fzyzcjy/feat/12786
Update docs
2 parents 6dd93d6 + 8d58363 commit 131f818

File tree

10 files changed

+102
-7
lines changed

10 files changed

+102
-7
lines changed

frb_example/flutter_package/example/pubspec.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@ packages:
297297
dependency: transitive
298298
description:
299299
name: web
300-
sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb
300+
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
301301
url: "https://pub.dev"
302302
source: hosted
303-
version: "1.1.0"
303+
version: "1.1.1"
304304
webdriver:
305305
dependency: transitive
306306
description:

frb_example/flutter_via_create/pubspec.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@ packages:
297297
dependency: transitive
298298
description:
299299
name: web
300-
sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb
300+
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
301301
url: "https://pub.dev"
302302
source: hosted
303-
version: "1.1.0"
303+
version: "1.1.1"
304304
webdriver:
305305
dependency: transitive
306306
description:

frb_example/flutter_via_integrate/pubspec.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@ packages:
297297
dependency: transitive
298298
description:
299299
name: web
300-
sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb
300+
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
301301
url: "https://pub.dev"
302302
source: hosted
303-
version: "1.1.0"
303+
version: "1.1.1"
304304
webdriver:
305305
dependency: transitive
306306
description:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Precompiled Rust Binaries
2+
3+
By default, flutter_rust_bridge uses Cargokit to do Rust compilation.
4+
Its default mode is to compile when the users build their apps.
5+
6+
However, if we want to ship pre-compiled Rust binaries in the Flutter package,
7+
this can be done by following https://github.com/irondash/cargokit/blob/main/docs/precompiled_binaries.md.

website/docs/guides/miscellaneous/codec.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ and SSE for both directions.
2323

2424
Currently, CST+DCO is the default choice. To use SSE instead, specify `#[frb(serialize)]` to your function.
2525
(The attribute syntax may be changed in the future, but should be as minimal as changing the name.)
26+
On the other hand, if `full_dep` is false,
27+
i.e. users are not required to install full dependencies like LLVM in order to use flutter_rust_bridge,
28+
then CST+DCO codec cannot be enabled and SSE is used.
2629

27-
For simplicity of implementation, Rust-Call-Dart uses DCO+SSE and cannot be changed currently,
30+
Some features are not implemented in both codecs for simplicity of implementation.
31+
For example, Rust-Call-Dart uses DCO+SSE and cannot be changed currently,
2832
but this should usually be no problem.
2933
If you find any difficulties due to this, feel free to create an issue.
3034

website/docs/guides/third-party/manual/external-types.md

+68
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,71 @@ pub struct FId(pub [u8; 32]);
8989
#[frb(mirror(MessageId, BlobId, FeedId))]
9090
pub struct Id(pub [u8; 32]);
9191
```
92+
93+
## Traits
94+
95+
Before flutter_rust_bridge supports more advanced parsing,
96+
traits in external third-party packages can be utilized
97+
through a proxy/wrapper/newtype design pattern as illustrated through the following example.
98+
99+
### Example
100+
101+
In this example,
102+
assume there is an external crate/package called 'calc' that contains a trait by name `Calc` (and an implementation `CalcImpl`),
103+
and we demonstrate how to use this trait and implementation in our `flutter_rust_bridge` based package.
104+
105+
#### External crate
106+
107+
*<external_crate>/calc.rs* :
108+
109+
```rust
110+
pub trait Calc {
111+
fn add(&self, a: u32, b: u32) -> u32;
112+
}
113+
114+
pub struct CalcImpl {}
115+
116+
impl Calc for CalcImpl {
117+
fn add(&self, a: u32, b: u32) -> u32 {
118+
a + b
119+
}
120+
}
121+
```
122+
123+
#### Our crate
124+
125+
##### Scenario 1
126+
127+
*rust/src/api/calc.rs*
128+
129+
```rust
130+
pub fn new_calc() -> Box<dyn Calc> {
131+
Box::new(CalcImpl {})
132+
}
133+
```
134+
135+
Then we get an opaque object about `Calc`, which can be passed back to Rust functions.
136+
137+
##### Scenario 2
138+
139+
If we want to have the methods on the `Calc` trait exposed as methods in Dart,
140+
one approach is to use Rust's commonly-seen proxy/wrapper/newtype design pattern as follows.
141+
142+
*rust/src/api/calc.rs*
143+
144+
```rust
145+
// So-called "newtype" pattern
146+
pub struct CalcWrapper(Box<dyn Calc + Send + Sync>);
147+
148+
impl CalcWrapper {
149+
pub fn new() -> Self {
150+
Self(Box::new(CalcImpl {})) // or whatever else...
151+
}
152+
153+
pub fn add(&self, a: u32, b: u32) -> u32 {
154+
self.0.add(a, b)
155+
}
156+
}
157+
```
158+
159+
This should work now as you have an equivalent type in `dart` to use all those member methods / functions in the underlying Rust trait.

website/docs/manual/integrate/05-template/index.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Use code template to create new projects
22

3+
:::info
4+
This guide was written for flutter_rust_bridge v1, thus some content may be outdated.
5+
The quickest approach to integrate is to follow the one-click approach in flutter_rust_bridge's quickstart page.
6+
:::
7+
38
In this chapter, we are going to use create your own project from a code template. It seems a bit long, but it is just because we have tried to describe *every detail* that you may encounter.
49

510
**Remark:** Most complexity does *not* come from this library, `flutter_rust_bridge` - it is as same complex as using raw Dart/Flutter FFI with Rust. In other words, it is the Dart/Flutter + Rust toolchain that takes time to set up.

website/docs/manual/integrate/06-existing/index.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Use BrickHub to add to existing projects
22

3+
:::info
4+
This guide was written for flutter_rust_bridge v1, thus some content may be outdated.
5+
The quickest approach to integrate is to follow the one-click approach in flutter_rust_bridge's quickstart page.
6+
:::
7+
38
This guide is an intermediate-level introduction to integrating Rust with
49
an existing Flutter project. If you are new to Rust or configuring
510
build processes in general, we suggest looking at [the template tour](template/tour)

website/docs/manual/integrate/07-library/index.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Creating a Dart/Flutter library with binary release
22

3+
:::info
4+
This guide was written for flutter_rust_bridge v1, thus some content may be outdated.
5+
The quickest approach to integrate is to follow the one-click approach in flutter_rust_bridge's quickstart page.
6+
:::
7+
38
In this chapter, we discuss how to add `flutter_rust_bridge` (FRB)
49
to an already existing application or create a new application from scratch;
510
this section covers creating a Dart-only library with a Flutter wrapper library on top.

website/sidebars.js

+1
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ const sidebars = {
412412
'guides/how-to/object-pool',
413413
'guides/how-to/gitignore',
414414
'guides/how-to/rust-compilation',
415+
'guides/how-to/precompiled-rust',
415416
'guides/how-to/cargo-workspaces',
416417
'guides/how-to/cross-origin',
417418
'guides/how-to/transferable-typed-data',

0 commit comments

Comments
 (0)