File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -64,9 +64,10 @@ defprotocol Inspect do
64
64
65
65
* `:except` - remove the given fields when inspecting.
66
66
67
- * `:optional` - (since v1.14.0) do not include a field if it
68
- matches its default value. This can be used to simplify the
69
- struct representation at the cost of hiding information.
67
+ * `:optional` - (since v1.14.0) a list of fields that should not be
68
+ included when they match their default value. This can be used to
69
+ simplify the struct representation at the cost of hiding
70
+ information.
70
71
71
72
Whenever `:only` or `:except` are used to restrict fields,
72
73
the struct will be printed using the `#User<...>` notation,
@@ -82,7 +83,15 @@ defprotocol Inspect do
82
83
#=> #User<id: 1, name: "Jane", ...>
83
84
84
85
If you use only the `:optional` option, the struct will still be
85
- printed as `%User{...}`.
86
+ printed as a valid struct.
87
+
88
+ defmodule Point do
89
+ @derive {Inspect, optional: [:z]}
90
+ defstruct [x: 0, y: 0, z: 0]
91
+ end
92
+
93
+ inspect(%Point{x: 1})
94
+ %Point{x: 1, y: 0}
86
95
87
96
## Custom implementation
88
97
You can’t perform that action at this time.
0 commit comments