@@ -1317,7 +1317,10 @@ defmodule GuardedStruct do
1317
1317
def builder ( attrs , error \\ false )
1318
1318
1319
1319
def builder ( { key , attrs } = input , error )
1320
- when is_tuple ( input ) and is_map ( attrs ) and ( is_list ( key ) or is_atom ( key ) ) do
1320
+ when is_tuple ( input ) and ( is_map ( attrs ) or is_struct ( attrs ) ) and
1321
+ ( is_list ( key ) or is_atom ( key ) ) do
1322
+ attrs = if ( is_struct ( attrs ) , do: Map . from_struct ( attrs ) , else: attrs )
1323
+
1321
1324
GuardedStruct . builder (
1322
1325
% { attrs: attrs , module: unquote ( module ) , revaluation: unquote ( escaped_list ) } ,
1323
1326
key ,
@@ -1327,7 +1330,10 @@ defmodule GuardedStruct do
1327
1330
end
1328
1331
1329
1332
def builder ( { key , attrs , type } = input , error )
1330
- when is_tuple ( input ) and is_map ( attrs ) and ( is_list ( key ) or is_atom ( key ) ) do
1333
+ when is_tuple ( input ) and ( is_map ( attrs ) or is_struct ( attrs ) ) and
1334
+ ( is_list ( key ) or is_atom ( key ) ) do
1335
+ attrs = if ( is_struct ( attrs ) , do: Map . from_struct ( attrs ) , else: attrs )
1336
+
1331
1337
GuardedStruct . builder (
1332
1338
% { attrs: attrs , module: unquote ( module ) , revaluation: unquote ( escaped_list ) } ,
1333
1339
key ,
@@ -1336,7 +1342,9 @@ defmodule GuardedStruct do
1336
1342
)
1337
1343
end
1338
1344
1339
- def builder ( attrs , error ) when is_map ( attrs ) do
1345
+ def builder ( attrs , error ) when is_map ( attrs ) or is_struct ( attrs ) do
1346
+ attrs = if ( is_struct ( attrs ) , do: Map . from_struct ( attrs ) , else: attrs )
1347
+
1340
1348
GuardedStruct . builder (
1341
1349
% { attrs: attrs , module: unquote ( module ) , revaluation: unquote ( escaped_list ) } ,
1342
1350
:root ,
0 commit comments