Skip to content

Commit dee2bc6

Browse files
authored
add @serdeProxyCast, @serdeEnumProxy UDAs
Implementation is needed on the mir-ion side for use though
1 parent 88d99b6 commit dee2bc6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

source/mir/serde.d

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module mir.serde;
1313

1414
import mir.functional: naryFun;
1515
import mir.reflection;
16+
import std.meta: AliasSeq;
1617
import std.traits: TemplateArgsOf, EnumMembers, hasUDA, isAggregateType;
1718

1819
version (D_Exceptions)
@@ -652,6 +653,13 @@ version(mir_test) unittest
652653
+/
653654
alias serdeGetProxy(alias symbol) = TemplateArgsOf!(getUDA!(symbol, serdeProxy))[0];
654655

656+
/// Can be applied to @serdeProxy types to make (de)serialization use
657+
/// underlying type through casting. Useful for enums.
658+
enum serdeProxyCast;
659+
660+
/// Equivalent to @serdeProxy!T @serdeProxyCast
661+
alias serdeEnumProxy(T) = AliasSeq!(serdeProxy!T, serdeProxyCast);
662+
655663
/++
656664
Can be applied only to fields that can be constructed from strings.
657665
Does not allocate new data when deserializeing. Raw data is used for strings instead of new memory allocation.

0 commit comments

Comments
 (0)