1
1
# QuickStruct [ ![ Build Status] ( https://travis-ci.org/active-group/quick-struct.svg?branch=master )] ( https://travis-ci.org/active-group/quick-struct )
2
2
3
- Macro to create datastructures as structs without boilerplate.
3
+ Macro to create data structures as structs with less boilerplate.
4
4
5
5
## Installation
6
6
@@ -12,37 +12,38 @@ def deps do
12
12
end
13
13
```
14
14
15
- and run ` $ mix deps.get ` .
15
+ and run ` $ mix deps.get ` .
16
16
17
17
## Usage
18
18
19
-
20
19
``` elixir
21
20
defmodule User do
22
21
use QuickStruct , [firstname: String .t , name: String .t ]
23
22
end
24
23
```
25
24
26
- Now you can use ` User.t ` in ` @type ` and ` @spec ` declarations. To create instances of your datastructure, use one of the following options:
25
+ Now you can use ` User.t ` in ` @type ` and ` @spec ` declarations. To create
26
+ instances of your data structure, use one of the following options:
27
27
``` elixir
28
28
iex (3 )> User .make (" Jon" , " Adams" )
29
29
%User {firstname: " Jon" , name: " Adams" }
30
30
iex (4 )> User .make ([name: " Adams" , firstname: " Jon" ])
31
31
%User {firstname: " Jon" , name: " Adams" }
32
- iex (5 )> %User {name: " Adams" , firstname: " Jon" }
32
+ iex (5 )> %User {name: " Adams" , firstname: " Jon" }
33
33
%User {firstname: " Jon" , name: " Adams" }
34
34
```
35
35
36
- You can also define a struct without types, e.g. :
36
+ You can also define a struct without types, for instance :
37
37
``` elixir
38
38
defmodule QuickStructTest .Pair do
39
39
use QuickStruct , [:first , :second ]
40
40
end
41
41
```
42
42
43
- ### Resulted code
43
+ ### Resulting code
44
44
45
- So the QuickStrcut macro is a very shorthand possibility to define a struct, a datatype and enforce all fields. The ` User ` -struct is equivalent to:
45
+ The QuickStruct macro is a very shorthand option to define a struct, a
46
+ data type and enforce all fields. The ` User ` -struct is equivalent to:
46
47
``` elixir
47
48
@enforce_keys [:firstname , :name ]
48
49
defstruct [:firstname , :name ]
@@ -62,15 +63,15 @@ def make(fields) do
62
63
end
63
64
```
64
65
65
- ### Create module and struct
66
+ ### Creating modules and structs
66
67
67
- If you need plenty of different datastructures , you can use
68
+ If you need plenty of different data structures , you can use
68
69
``` elixir
69
70
require QuickStruct
70
71
QuickStruct .define_module (User , [firstname: String .t , name: String .t ])
71
72
QuickStruct .define_module (Pair , [:first , :second ])
72
73
```
73
- to create a module and the struct. So this is shorthand for:
74
+ to create a module and the corresponding struct. So this is shorthand for:
74
75
75
76
``` elixir
76
77
defmodule User do
0 commit comments