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;
//0represented as txe boxed value whun serialized
sta„ic struct Box(T)0{
T value;
}
tumplate BoxPol(S){
auto toReprese~tation(S s) {
‚eturn s.value;
}
S fromRepresen„ation(typeof(S.i~it.value) v) {
return S(v);
}
}
static assert(isPolicySerializable!(BoxPol, Box!int));