-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Extra Dart code | ||
|
||
Arbitrary extra Dart code can be inserted into auto-generated Dart classes. | ||
|
||
## Example | ||
|
||
```rust | ||
#[frb(dart_code = " | ||
int extraMethod() => a * 2; | ||
" | ||
)] | ||
pub struct MyStruct { | ||
... | ||
} | ||
``` | ||
|
||
Then the generated Dart class will look like: | ||
|
||
```dart | ||
class MyStruct { | ||
... // other auto-generated code | ||
int extraMethod() => a * 2; // The extra code | ||
} | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Equals and Hash | ||
|
||
This page discusses the `operator==` (equals) and `hashCode` of the automatically generated Dart class. | ||
|
||
## Default | ||
|
||
The default for non-`freezed` classes is field-by-field comparison. | ||
You can use `#[frb(non_hash, non_eq)]` to disable such generated code. | ||
|
||
The default for `freezed` classes: Usually field-by-field comparison (see `freezed`'s doc for more details). | ||
|
||
## Custom (arbitrary) | ||
|
||
Arbitrary equals/hash function can also be implemented by using the [extra Dart code](dart-code) feature. | ||
For example, `#[frb(dart_code = "int get hashCode { arbitrary_code_calling_whatever_Rust_and_Dart_things }")]`. |
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