I am working on a project that has several structs that hold related information (think objects). Most of the types in these structs are basic types such as String
, f64
, etc, but I am using types from the Dimensioned
package and also Rc<RefCell<>>
types. There are also Vec
and HashMap
fields.
In a library function, I read in data from files using serde
then reconstruct that into my proper types along with reference counted references to other structs (I have datatypes that can either be a type or instance of a type(think of a struct that holds info common to a specific model of laptop, and then another one that hold info common to a single laptop, that might have a reference to one of several different laptop models), and several instances can refer to one type). During this reconstruction, there might be 2 instances of a defined instance or type read in from different datafiles, and I want to be able to prompt a user to merge these 2 instances at the end of parsing and reconstruction.
Currently, I have defined a method on each type that compares the fields of two of the same type, prompts the user to perform a manual merge between them, and then does the actual merge logic. Since these methods vary in length, depending on the total number of fields in the structs, these functions get tedious to manually write, and keep updated if I add a new field to the structs.
I decided to mitigate this tedium by writing a derive proc-macro that generates these methods for me, but am running into issues with the complex types, specifically that I need to special case the Vec
and HashMap
types so I can string their contents together, rather than just using display()
or to_string()
. I cannot figure out how to do this using syn
. I am also having weird issues with Option<>
and the dimensioned
types, where I get errors complaning that you cannot chain comparison symbols during cargo --expand
I can't just compare 2 objects directly, since they may have the same ID, but different contents unfortunately.
i would appreciate assistance with either/or:
- a solution for special casing the troublesome types in my proc-macro
- a solution for this merging process that wouldn't rely on proc-macros or manually writing long boilerplate macros that are tricky to update.
Source code is on github here.
Thank you