Say that I have two custom option types, TypeA
and TypeB
defined below:
using Configurations
@option "type_a" struct TypeA
type::Reflect
a::Int
end
@option "type_b" struct TypeB
type::Reflect
b::Int
end
And I also have an option type that holds a vector of type Union{TypeA, TypeB}
:
@option struct VectorType
vec::Vector{Union{TypeA,TypeB}}
end
I’m am currently able to create a .toml file using this type as follows:
test_vec = VectorType([TypeA(Reflect(), 1), TypeB(Reflect(), 2)])
to_toml(joinpath(@__DIR__, "test.toml"), test_vec)
which creates test.toml as:
[[vec]]
type = "type_a"
a = 1
[[vec]]
type = "type_b"
b = 2
However I am unable to read the .toml back into my custom type:
test_vec = from_toml(VectorType, joinpath(@__DIR__, "test.toml"))
ERROR: ArgumentError: cannot parse type_a to a Julia type
Stacktrace:
[1] parse_jltype(s::String, alias_map::Nothing)
@ Configurations ~/.julia/packages/Configurations/Yxczn/src/utils.jl:46
[2] macro expansion
@ ~/.julia/packages/Configurations/Yxczn/src/from_dict.jl:430 [inlined]
[3] from_dict_union_type(#unused#::Type{VectorType}, #unused#::OptionField{:vec}, #unused#::Type{Union{TypeA, TypeB}}, value::Dict{String, Any})
@ Configurations ~/.julia/packages/Configurations/Yxczn/src/from_dict.jl:170
[4] (::Configurations.var"#7#9"{VectorType, Vector{Union{TypeA, TypeB}}, OptionField{:vec}})(each::Dict{String, Any})
@ Configurations ~/.julia/packages/Configurations/Yxczn/src/from_dict.jl:133
[5] iterate
@ ./generator.jl:47 [inlined]
Is this possible in the Configuration.jl package. Any help is appreciated.
Thanks!