You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a macro that can automatically implement Defaults.Serializable for user-defined custom structures.
Motivation
Implementing Defaults.Serializable for custom structures every time can be annoying and leads to redundant code.
For nested structures, developers need to implement it for each struct individually.
Having a macro to handle this automatically would greatly improve efficiency and reduce repetitive work.
Detailed design
Here is an example of the macro, currently named @DefaultSerializable.
@DefaultsSerializablestructUser{letname:Stringletage:Int}
// Generated
extensionUser:Defaults.Serializable{staticletbridge=UserBridge()structUserBridge:Defaults.Bridge{typealiasValue=UsertypealiasSerializable=[String:String]publicfunc serialize(_ value:Value?)->Serializable?{guardlet value else{returnnil}return["name": value.name,"age": value.age
]}publicfunc deserialize(_ object:Serializable?)->Value?{guardlet object,let name =object["name"],let age =object["age"]else{returnnil}returnUser(
name: name,
age: age
)}}}
Stage
Since this is a large macro, I would like to split the implementation into the following stages:
Stage 1
Implement @DefaultSerializable only.
Stage 2
Implement common used field attributes such as skip (The member should be an Optional to apply skip attribute).
Stage 3
Implement skip_serializaing_if/skip_deserializaing_if (Not quite sure whether this can be achieved or not; further investigation is needed.)
Stage ?
Implement rename-related fields (though I’m not entirely sure whether this will be useful in our case, as we should always use Defaults to access them 🤔)."
Conclusion
The ultimate goal is to implement all attributes mentioned in the serde attributes.
Note that this is still in the early stages.
Any feedback is welcome!
The text was updated successfully, but these errors were encountered:
Introduction
Create a macro that can automatically implement
Defaults.Serializable
for user-defined custom structures.Motivation
Implementing
Defaults.Serializable
for custom structures every time can be annoying and leads to redundant code.For nested structures, developers need to implement it for each struct individually.
Having a macro to handle this automatically would greatly improve efficiency and reduce repetitive work.
Detailed design
Here is an example of the macro, currently named
@DefaultSerializable
.Stage
Since this is a large macro, I would like to split the implementation into the following stages:
Stage 1
Implement
@DefaultSerializable
only.Stage 2
Implement common used field attributes such as
skip
(The member should be an Optional to apply skip attribute).Stage 3
Implement
skip_serializaing_if/skip_deserializaing_if
(Not quite sure whether this can be achieved or not; further investigation is needed.)Stage ?
Implement
rename
-related fields (though I’m not entirely sure whether this will be useful in our case, as we should always useDefaults
to access them 🤔)."Conclusion
The ultimate goal is to implement all attributes mentioned in the serde attributes.
Note that this is still in the early stages.
Any feedback is welcome!
The text was updated successfully, but these errors were encountered: