I have a struct (let’s say
Model) where I would like to logically divide the fields in two different objects (lets’s say
optionsb) but I want to keep this division transparent to the user so that it can just call the main structure using keyword arguments of the two wrapped structures. Of course, I could write a custom constructor with all the fields of the wrapped structs, but I wonder if there is a way to do it automatically.
Base.@kwdef mutable struct OptionsA option1a::Int64 = 0 option2a::String = "foo" end Base.@kwdef mutable struct OptionsB option1b::Int64 = 1 option2b::String = "boo" end mutable struct Model optionsa::OptionsA optionsb::OptionsB otherstuff end # User should be able to do any of the following: Model() Model(option1a=1) Model(option1a=1,option2b="zzz") ...