Thank you both! `Macro.struct!/2` is perfect for my needs. ~Marten/Qqwy
On Friday, November 19, 2021 at 11:14:22 PM UTC+1 José Valim wrote: > There is Macro.struct!(module, env), which will expand the struct for a > given module accordingly and most likely what you would want to use. > > On Fri, Nov 19, 2021 at 11:10 PM 'eksperimental' via elixir-lang-core < > elixir-l...@googlegroups.com> wrote: > >> Hi Marten, >> You will find this PR interesting >> https://github.com/elixir-lang/elixir/issues/10352 >> >> Cheers, >> - Eks >> >> On Fri, 19 Nov 2021 14:00:40 -0800 (PST) >> "w...@resilia.nl" <w...@resilia.nl> wrote: >> >> > Hi all! >> > >> > I recently needed to check what fields for a struct were defined (if >> > any) for a particular module, at compile-time (potentially in the >> > body of that module, i.e. while the module was still 'open'). >> > *(for the curious, it's part of code that builds a runtime type-check >> > from a typespec, see here >> > < >> https://github.com/Qqwy/elixir-type_check/blob/21d5de5a1979ebd10d0f30818b6e837062027269/lib/type_check/internals/pre_expander.ex#L265-L270 >> >)* >> > >> > There was no information in Elixir's documentation about this. >> > Looking at the source of `defstruct` >> > < >> https://github.com/elixir-lang/elixir/blob/79cd891eb86ecb7654a7acdb63769cfdd950a5c0/lib/elixir/lib/kernel.ex#L5037-L5046> >> >> >> > we however find that it defines a `@__struct__` module attribute >> > (which is then later on used to implement the introspection method >> > `__struct__/0`). >> > >> > Now the question is: Is it OK for libraries to depend on >> > `@__struct__` or should it be considered an implementation detail >> > which is subject to change? >> > >> > -If it's OK: Should we maybe add a sentence to the module >> > documentation of `Module`? Or the documentation of >> > `Kernel.SpecialForms.%/2`? >> > - If it's not: Is there a 'proper' way to obtain this information for >> > an 'open' module instead? >> > >> > Thank you all, >> > >> > ~Marten/Qqwy >> > >> >> -- >> You received this message because you are subscribed to the Google Groups >> "elixir-lang-core" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to elixir-lang-co...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/elixir-lang-core/619820bd.1c69fb81.8c1b5.36d4SMTPIN_ADDED_MISSING%40gmr-mx.google.com >> . >> > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/07fa8fbf-6597-40d4-9ccc-ddfc380ea54an%40googlegroups.com.