Skip to content

Commit 37495d5

Browse files
authored
Merge pull request #14 from ExpressApp/inplace-definition
fix define structure via using
2 parents 19f9dd9 + 60945eb commit 37495d5

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
## Changelog
22

3+
## v1.2.1
4+
5+
* Bug fixes
6+
* Fix define structure via using
7+
38
## v1.2.0
49

510
* Enhancements
611
* Add `struct` type
712

813
## v1.1.1
14+
915
* Enhancements
1016
* Definition in using macro
1117
* Add able to override fields

lib/construct.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ defmodule Construct do
3131

3232
@doc false
3333
defmacro __using__(opts \\ []) do
34-
definition = Keyword.get(opts, :do)
34+
{definition, opts} = Keyword.pop(opts, :do)
3535

36-
structure =
36+
pre_ast =
3737
if definition do
3838
defstructure(definition)
3939
else
40-
[]
40+
quote do
41+
import Construct, only: [structure: 1]
42+
end
4143
end
4244

4345
quote do
4446
@behaviour Construct
4547

46-
import Construct, only: [structure: 1]
47-
48-
unquote(structure)
48+
unquote(pre_ast)
4949

5050
@type t :: %__MODULE__{}
5151

0 commit comments

Comments
 (0)