Skip to content

Commit

Permalink
Return _field_types
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKlo committed Jan 6, 2025
1 parent e4b9706 commit d892204
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/De/Deser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ function deser(::DictType, ::Type{T}, data::AbstractDict{K,D})::T where {T<:Abst
return target
end

_field_types(::Type{T}) where {T} = Tuple(fieldtype(T, x) for x in fieldnames(T))

@inline function eldeser(ct::Type, ft::Type, key::K, data::D) where {K,D}
try
return data isa ft ? data : deser(ct, ft, data)
Expand All @@ -371,7 +373,7 @@ end
function deser(::CustomType, ::Type{T}, data::AbstractVector{A})::T where {T<:Any,A<:Any}
target = Vector{Any}(undef, fieldcount(T))
index::Int = 0
for (type, name) in zip(fieldtypes(T), fieldnames(T))
for (type, name) in zip(_field_types(T), fieldnames(T))
index += 1
key = custom_name(T, Val(name))
val = get(data, index, nulltype(type))
Expand All @@ -384,7 +386,7 @@ end
function deser(::CustomType, ::Type{T}, data::AbstractDict{K,D})::T where {T<:Any,K<:Union{AbstractString,Symbol},D<:Any}
target = Vector{Any}(undef, fieldcount(T))
index::Int = 0
for (type, name) in zip(fieldtypes(T), fieldnames(T))
for (type, name) in zip(_field_types(T), fieldnames(T))
index += 1
key = deser(keytype(data), custom_name(T, Val(name)))
val = get(data, key, default_value(T, Val(name)))
Expand All @@ -397,7 +399,7 @@ end
function deser(::CustomType, ::Type{T}, data::N)::T where {T<:Any,N<:NamedTuple}
target = Vector{Any}(undef, fieldcount(T))
index::Int = 0
for (type, name) in zip(fieldtypes(T), fieldnames(T))
for (type, name) in zip(_field_types(T), fieldnames(T))
index += 1
key = custom_name(T, Val(name))
val = get(data, key, default_value(T, Val(name)))
Expand Down

0 comments on commit d892204

Please sign in to comment.