Enum member isPolicySerializable
Checks if a given policy supports custom serialization for a given type.
enum isPolicySerializable(alias Policy, T)
= is(typeof(Policy!T .toRepresentation(T .init))) && is(typeof(Policy!T .fromRepresentation(Policy!T .toRepresentation(T .init))) : T);
A class or struct type is custom serializable according to a policy if
the policy defines a pair of toRepresentation
/fromRepresentation
functions. Any class or struct type that has this trait for the policy supplied to
serializeWithPolicy
will be serialized by using the return value of the
policy toRepresentation
function instead of the original value.
This trait has precedence over isCustomSerializable
,
isISOExtStringSerializable
and isStringSerializable
.
See Also
Example
import std .conv;
// represented as the boxed value when serialized
static struct Box(T) {
T value;
}
template BoxPol(S)
{
auto toRepresentation(S s) {
return s .value;
}
S fromRepresentation(typeof(S .init .value) v) {
return S(v);
}
}
static assert(isPolicySerializable!(BoxPol, Box!int));