The issue
I read data from a file that is meant to be attached to a tree-like structure. Each line of the file contains attributes about a node of the tree.
Three attributes are mandatory (and are immutable), and the user can give any other attribute. The attributes given by the user can be anything, but we know their name and their type at import because they are given in the file.
When the tree is complete, in a typical use case some fields of the nodes are only read, but some are modified.
I am currently using a Dict{String,Any} to store the user-defined data in my node struct, but I know it is not advisable for performance. This is especially important to consider because a lot of computations are made afterward.
My current struct has two fields, one for the mandatory attributes related to any nodes (they are immutable), and one for further attributes given in the file. The struct looks like this:
mutable struct Node1
attr1::Node2
attr2
end
The immutable struct from the first field of Node1 looks like the following:
struct Node2
link::AbstractString
symbol::Union{Missing,AbstractString}
index::Union{Missing,Integer}
end
The question
Now here is my question: can I do any better ?
For example, could I make programmatically my Node1 struct with fields based on the attributes given in the file ? That would allow me to at least give the type of each attribute instead of just Any.