Skip to content

Commit

Permalink
chore: doc
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy committed Apr 7, 2024
1 parent 37126a5 commit 77ad8d8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
25 changes: 25 additions & 0 deletions website/docs/guides/miscellaneous/dart-code.md
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
}
```
15 changes: 15 additions & 0 deletions website/docs/guides/miscellaneous/eq-hash.md
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 }")]`.
2 changes: 2 additions & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ const sidebars = {
'guides/miscellaneous/callables',
'guides/miscellaneous/properties',
'guides/miscellaneous/constructors',
'guides/miscellaneous/dart-code',
'guides/miscellaneous/eq-hash',
'guides/miscellaneous/codec',
'guides/miscellaneous/build-rs',
'guides/miscellaneous/expanding-macros',
Expand Down

0 comments on commit 77ad8d8

Please sign in to comment.