From 34fae89e3590a232b8a0368045767da3a2c1f791 Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Tue, 13 Apr 2021 21:45:45 -0600 Subject: [PATCH] Define StructType for Some as CustomStruct (#45) * Define StructType for Some as CustomStruct Brought up in https://github.com/quinnj/JSON3.jl/issues/143. This is basically the exact use-case for `CustomStruct`. * fix tests --- src/StructTypes.jl | 4 ++++ test/runtests.jl | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/StructTypes.jl b/src/StructTypes.jl index 6000fe2..4d69ee2 100644 --- a/src/StructTypes.jl +++ b/src/StructTypes.jl @@ -51,6 +51,10 @@ function lowertype end lowertype(::Type{T}) where {T} = Any +StructType(::Type{Some{T}}) where {T} = CustomStruct() +lower(x::Some) = x.value +lowertype(::Type{Some{T}}) where {T} = T + "A kind of `StructType` where an object's \"data\" is made up, at least in part, by its direct fields. When serializing, appropriate fields will be accessed directly." abstract type DataType <: StructType end diff --git a/test/runtests.jl b/test/runtests.jl index 9618183..5eccadd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -119,6 +119,9 @@ x = "499beb72-22ea-11ea-3366-55749430b981" v = v"1.2.3" @test StructTypes.StructType(v) == StructTypes.StringType() +# Some wrapper +@test StructTypes.StructType(Some(1)) == StructTypes.CustomStruct() + end struct B