Skip to content

Commit 13cd182

Browse files
committed
add serde.isAnnotated
1 parent 53ed807 commit 13cd182

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

source/mir/serde.d

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,26 @@ enum serdeRegister;
145145
/++
146146
The attribute can be applied to a string-like member that should be de/serialized as an annotation / attribute.
147147
148-
Also, the attribute can be applied to on a type used in an algebraic type to denote that the type should be used to deserialize annotated value.
148+
Also, the attribute can be applied on a type to denote that the type should be used to de/serialize annotated value.
149149
150150
This feature is used in $(MIR_PACKAGE mir-ion).
151151
+/
152152
enum serdeAnnotation;
153153

154+
/++
155+
Checks if the type marked with $(LREF serdeAnnotation).
156+
+/
157+
template isAnnotated(T)
158+
{
159+
import mir.serde: serdeAnnotation;
160+
static if (is(T == enum) || isAggregateType!T) {
161+
enum isAnnotated = hasUDA!(T, serdeAnnotation);
162+
static if (isAnnotated)
163+
static assert(__traits(getAliasThis, T).length == 1 || __traits(hasMember, T, "value"), "@serdeAnnotation " ~ T.stringof ~" requires alias this member or `value` member.");
164+
}
165+
else
166+
enum isAnnotated = false;
167+
}
154168

155169
private template serdeIsAnnotationMemberIn(T)
156170
{

0 commit comments

Comments
 (0)