chaokunyang commented on code in PR #3092:
URL: https://github.com/apache/fory/pull/3092#discussion_r2647138123
##########
rust/fory-derive/src/object/serializer.rs:
##########
@@ -269,72 +271,90 @@ fn generate_default_impl(
match &ast.data {
Data::Struct(s) => {
- let fields = sorted_fields(&s.fields);
+ let sorted = sorted_fields(&s.fields);
+ let fields = fields_only(&sorted);
let is_tuple_struct = super::util::is_tuple_struct(&fields);
use super::util::{
classify_trait_object_field, create_wrapper_types_arc,
create_wrapper_types_rc,
StructField,
};
- let field_inits: Vec<_> = fields
- .iter()
- .map(|field| {
- let ident = &field.ident;
- let ty = &field.ty;
-
- match classify_trait_object_field(ty) {
- StructField::RcDyn(trait_name) => {
- let types = create_wrapper_types_rc(&trait_name);
- let wrapper_ty = types.wrapper_ty;
- let trait_ident = types.trait_ident;
- let value = quote! {
- {
- let wrapper = #wrapper_ty::default();
- std::rc::Rc::<dyn
#trait_ident>::from(wrapper)
+ // For tuple structs, we need to order field inits by original
index.
+ let field_inits: Vec<_> = if is_tuple_struct {
Review Comment:
If we add a name field to `FieldInfo`(`SortedField` in this pr), could we
unify the two branch here?
Introducing two big branch is error-prone, we may forget to update one of
rbanch inthe future.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]