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

RFC: Add macros for setting StructType #65

Closed mmiller-max closed 3 years ago

mmiller-max commented 3 years ago

Adds macros to define StructTypes, see #64

Example use:

help?> StructTypes.@Struct
  @StructTypes.Struct(expr::Expr)
  @StructTypes.Struct(expr::Symbol)

  If expr is a struct definition, sets the StructType of the defined struct to StructTypes.Struct(). If expr is the name of a Type,
  sets the StructType of that type to StructTypes.Struct().

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  @StructTypes.Struct MyStruct

  is equivalent to

  StructTypes.StructType(::Type{MyStruct}) = StructType.Struct()

  and

  @StructTypes.Struct struct MyStruct
      val::Int
  end

  is equivalent to

  struct MyStruct
      val::Int
  end
  StructTypes.StructType(::Type{MyStruct}) = StructType.Struct()

Ideally they would be exported as well, to minimise how much typing was required.

If this seems something we would want I'll add tests and docs.

mmiller-max commented 3 years ago

Changed the docs (it had @StructTypes.Struct before) and improved the wording in the error messages. Do you want me add something to the docs, and is it worth exporting the macros too?

codecov[bot] commented 3 years ago

Codecov Report

Merging #65 (7e62529) into main (cc49757) will increase coverage by 0.70%. The diff coverage is 90.90%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #65      +/-   ##
==========================================
+ Coverage   72.83%   73.53%   +0.70%     
==========================================
  Files           1        2       +1     
  Lines         346      359      +13     
==========================================
+ Hits          252      264      +12     
- Misses         94       95       +1     
Impacted Files Coverage Δ
src/StructTypes.jl 72.98% <ø> (+0.15%) :arrow_up:
src/macros.jl 90.90% <90.90%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update cc49757...7e62529. Read the comment docs.