You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "ariesdevil (via GitHub)" <gi...@apache.org> on 2025/12/22 09:44:14 UTC
[PR] feat(rust): add generate_default attr, no longer generate Default by default [fory]
ariesdevil opened a new pull request, #3074:
URL: https://github.com/apache/fory/pull/3074
…default
<!--
**Thanks for contributing to Apache Fory™.**
**If this is your first time opening a PR on fory, you can refer to [CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).**
Contribution Checklist
- The **Apache Fory™** community has requirements on the naming of pr titles. You can also find instructions in [CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).
- Apache Fory™ has a strong focus on performance. If the PR you submit will have an impact on performance, please benchmark it first and provide the benchmark result here.
-->
## Why?
When using `#[derive(ForyObject)]` on a type that already has a manual `impl Default`, a compilation error occurs due to conflicting `Default` implementations. The previous behavior of auto-generating `Default` was problematic for integrating with existing codebases where types have custom `Default` implementations.
After discussion with reviewers, we decided to **invert the default behavior**: `ForyObject` should NOT generate `impl Default` by default, and users who want it can opt-in with `#[fory(generate_default)]`.
## What does this PR do?
### Breaking Change
`#[derive(ForyObject)]` **no longer generates `impl Default`** by default.
### Migration Guide
```rust
// Before this PR (v0.14.0)
#[derive(ForyObject)]
struct MyStruct { ... } // Auto-generates Default
// After this PR (v0.15.0) - Option 1: Add derive(Default) explicitly
#[derive(ForyObject, Default)]
struct MyStruct { ... }
// After this PR (v0.15.0) - Option 2: Use generate_default attribute
#[derive(ForyObject)]
#[fory(generate_default)]
struct MyStruct { ... }
```
### Changes
1. Added `#[fory(generate_default)]` attribute to opt-in for `Default` generation
2. Changed all internal code generation to use `ForyDefault::fory_default()` instead of `Default::default()`
3. Updated `register_trait_type!` macro to use `ForyDefault` instead of `Default`
4. Updated documentation and tests
5. Used workspace dependencies for internal crate versions
## Related issues
None
## Does this PR introduce any user-facing change?
- [x] Does this PR introduce any public API change?
- **Breaking**: `#[derive(ForyObject)]` no longer generates `impl Default`
- **New**: `#[fory(generate_default)]` attribute to opt-in for `Default` generation
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
This change only affects compile-time code generation. No runtime performance impact.
<!--
When the PR has an impact on performance (if you don't know whether the PR will have an impact on performance, you can submit the PR first, and if it will have impact on performance, the code reviewer will explain it), be sure to attach a benchmark data here.
Delete section if not applicable.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(rust): add generate_default attr, no longer generate Default by default [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #3074:
URL: https://github.com/apache/fory/pull/3074#discussion_r2639310742
##########
rust/README.md:
##########
@@ -26,13 +26,60 @@ The Rust implementation provides versatile and high-performance serialization wi
| [`fory-core`](https://github.com/apache/fory/blob/main/rust/fory-core/) | Core serialization engine | [](https://crates.io/crates/fory-core) |
| [`fory-derive`](https://github.com/apache/fory/blob/main/rust/fory-derive/) | Procedural macros | [](https://crates.io/crates/fory-derive) |
+## Breaking Change in v0.15.0
Review Comment:
I prefer not including this, we could put this into github pr description, and add it to next release note.
We could document at `#[derive(ForyObject)]` section that `ForyObject` will genetate `fory_default()` methdo, users can use `generate_default` to generate `default methods` too
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(rust): add generate_default attr, no longer generate Default by default [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #3074:
URL: https://github.com/apache/fory/pull/3074#discussion_r2639313482
##########
docs/guide/rust/custom-serializers.md:
##########
@@ -63,13 +63,17 @@ impl Serializer for CustomType {
}
}
+// ForyDefault delegates to Default
impl ForyDefault for CustomType {
fn fory_default() -> Self {
Self::default()
}
}
```
+> **Note**: When implementing `ForyDefault` manually, ensure your type also implements `Default` if you use `Self::default()`.
Review Comment:
Could we also document that users can make `ForyObject` to generate `default`too
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(rust): add generate_default attr, no longer generate Default by default [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang merged PR #3074:
URL: https://github.com/apache/fory/pull/3074
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(rust): add generate_default attr, no longer generate Default by default [fory]
Posted by "ariesdevil (via GitHub)" <gi...@apache.org>.
ariesdevil commented on PR #3074:
URL: https://github.com/apache/fory/pull/3074#issuecomment-3681337947
I also upgraded the crates version since that's a breaking change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(rust): add generate_default attr, no longer generate Default by default [fory]
Posted by "ariesdevil (via GitHub)" <gi...@apache.org>.
ariesdevil commented on PR #3074:
URL: https://github.com/apache/fory/pull/3074#issuecomment-3681324333
@chaokunyang Fixed, PTAL again
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org