Skip to content

Commit

Permalink
Define StructType for Some as CustomStruct (#45)
Browse files Browse the repository at this point in the history
* Define StructType for Some as CustomStruct

Brought up in quinnj/JSON3.jl#143. This is
basically the exact use-case for `CustomStruct`.

* fix tests
  • Loading branch information
quinnj authored Apr 14, 2021
1 parent 6a2d072 commit 34fae89
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/StructTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 34fae89

Please sign in to comment.