JuliaData / StructTypes.jl

Abstract definitions and convenience methods for describing, processing, and constructing Julia objects
https://juliadata.github.io/StructTypes.jl/stable/
MIT License
80 stars 22 forks source link

missing `constructfrom` method for `CustomStruct`? #69

Open ExpandingMan opened 2 years ago

ExpandingMan commented 2 years ago

Perhaps I'm misunderstanding the intention of CustomStruct but I believe it is missing a constructfrom method. Even after defining the required methods I get, e.g.

◖◗ ST.constructfrom(Dict{String,Any}, c)
ERROR: MethodError: no method matching constructfrom(::StructTypes.DictType, ::Type{Dict{String, Any}}, ::Type{String}, ::Type{Any}, ::StructTypes.CustomStruct, ::Column{Int64, Count})
Closest candidates are:
  constructfrom(::StructTypes.DictType, ::Type{T}, ::Type{K}, ::Type{V}, ::StructTypes.DictType, ::Any) where {T, K, V} at ~/.julia/packages/StructTypes/Cmlkm/src/StructTypes.jl:961
  constructfrom(::StructTypes.DictType, ::Type{T}, ::Type{K}, ::Type{V}, ::Union{StructTypes.Mutable, StructTypes.Struct}, ::Any) where {T, K, V} at ~/.julia/packages/StructTypes/Cmlkm/src/StructTypes.jl:978
  constructfrom(::StructTypes.DictType, ::Type{T}, ::Type{K}, ::Type{V}, ::S) where {T, K, V, S} at ~/.julia/packages/StructTypes/Cmlkm/src/StructTypes.jl:958
  ...
Stacktrace:
 [1] constructfrom
   @ ~/.julia/packages/StructTypes/Cmlkm/src/StructTypes.jl:958 [inlined]
 [2] constructfrom(#unused#::StructTypes.DictType, #unused#::Type{Dict{String, Any}}, obj::Column{Int64, Count})
   @ StructTypes ~/.julia/packages/StructTypes/Cmlkm/src/StructTypes.jl:955
 [3] constructfrom(#unused#::Type{Dict{String, Any}}, obj::Column{Int64, Count})
   @ StructTypes ~/.julia/packages/StructTypes/Cmlkm/src/StructTypes.jl:905
 [4] top-level scope
   @ REPL[13]:1

I had defined StructTypes.lowertype(::Type{<:Column}) = Dict{String,Any}, so I was expecting this to work.

ExpandingMan commented 2 years ago

It might help to explain a bit more what I'm trying to do: I have a type Column{T,S} and I would like to serialize T,S as strings, but they are not involved in any field of the struct. As far as I can tell, this precludes the use of StructTypes.Struct().